Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions rofs-filtered.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,29 @@ static int should_hide(const char *name, mode_t mode) {
}
if (conf.invert && mode != S_IFREG && mode != S_IFDIR)
return conf.invert;
if (!regexec(&pattern, name, 0, NULL, 0)) {
// We have a match.
log_msg(LOG_DEBUG, "match: %s", name);
return !conf.invert;

/* Append slash if directory */
if (mode == S_IFDIR) {
char *name_and_slash = malloc(strlen(name) + 2);
if (!name_and_slash) {
log_msg(LOG_DEBUG, "out of memory while handling %s", name);
return 0;
}
strcpy(name_and_slash, name);
strcat(name_and_slash, "/");
if (!regexec(&pattern, name_and_slash, 0, NULL, 0)) {
// We have a match.
log_msg(LOG_DEBUG, "match: %s", name_and_slash);
free(name_and_slash);
return !conf.invert;
}
free(name_and_slash);
} else {
if (!regexec(&pattern, name, 0, NULL, 0)) {
// We have a match.
log_msg(LOG_DEBUG, "match: %s", name);
return !conf.invert;
}
}
return conf.invert;
}
Expand Down Expand Up @@ -464,7 +483,7 @@ static int callback_readlink(const char *path, char *buf, size_t size) {
static int callback_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
if (should_hide(path, S_IFREG)) return -ENOENT;
if (should_hide(path, S_IFDIR)) return -ENOENT;

DIR *dp;
struct dirent *de;
Expand Down
6 changes: 3 additions & 3 deletions rofs-filtered.rc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# /file1.flac
# /file1.mp3
# /file2.mp3
# /subDir1
# /subDir1/
# /subDir1/file3.flac
# etc...
#
Expand All @@ -52,10 +52,10 @@
.*\.flac$

# Hide subDir2 (and all its contents), no matter where it appears in the tree:
/subDir2$
/subDir2/$

# Hide the subDir2 but only if it occurs at the root of the tree:
^/subDir2$
^/subDir2/$

# Since a RegEx can not start with '|' (vertical bar), this symbol is used to
# escape out of RegEx mode and introduce special configuration flags.
Expand Down