diff options
-rw-r--r-- | include/fstree.h | 8 | ||||
-rw-r--r-- | lib/fstree/fstree_from_dir.c | 46 |
2 files changed, 49 insertions, 5 deletions
diff --git a/include/fstree.h b/include/fstree.h index f6ff75f..193cecb 100644 --- a/include/fstree.h +++ b/include/fstree.h @@ -23,6 +23,14 @@ enum { DIR_SCAN_ONE_FILESYSTEM = 0x02, DIR_SCAN_NO_RECURSION = 0x04, + + DIR_SCAN_NO_SOCK = 0x0008, + DIR_SCAN_NO_SLINK = 0x0010, + DIR_SCAN_NO_FILE = 0x0020, + DIR_SCAN_NO_BLK = 0x0040, + DIR_SCAN_NO_DIR = 0x0080, + DIR_SCAN_NO_CHR = 0x0100, + DIR_SCAN_NO_FIFO = 0x0200, }; #define FSTREE_MODE_HARD_LINK (0) diff --git a/lib/fstree/fstree_from_dir.c b/lib/fstree/fstree_from_dir.c index fca916d..fe12b24 100644 --- a/lib/fstree/fstree_from_dir.c +++ b/lib/fstree/fstree_from_dir.c @@ -62,6 +62,35 @@ static int populate_dir(int dir_fd, fstree_t *fs, tree_node_t *root, goto fail; } + switch (sb.st_mode & S_IFMT) { + case S_IFSOCK: + if (flags & DIR_SCAN_NO_SOCK) + continue; + break; + case S_IFLNK: + if (flags & DIR_SCAN_NO_SLINK) + continue; + break; + case S_IFREG: + if (flags & DIR_SCAN_NO_FILE) + continue; + break; + case S_IFBLK: + if (flags & DIR_SCAN_NO_BLK) + continue; + break; + case S_IFCHR: + if (flags & DIR_SCAN_NO_CHR) + continue; + break; + case S_IFIFO: + if (flags & DIR_SCAN_NO_FIFO) + continue; + break; + default: + break; + } + if ((flags & DIR_SCAN_ONE_FILESYSTEM) && sb.st_dev != devstart) continue; @@ -81,11 +110,18 @@ static int populate_dir(int dir_fd, fstree_t *fs, tree_node_t *root, if (!(flags & DIR_SCAN_KEEP_TIME)) sb.st_mtime = fs->defaults.st_mtime; - n = fstree_mknode(root, ent->d_name, strlen(ent->d_name), - extra, &sb); - if (n == NULL) { - perror("creating tree node"); - goto fail; + if (S_ISDIR(sb.st_mode) && (flags & DIR_SCAN_NO_DIR)) { + n = fstree_get_node_by_path(fs, root, ent->d_name, + false, false); + if (n == NULL) + continue; + } else { + n = fstree_mknode(root, ent->d_name, + strlen(ent->d_name), extra, &sb); + if (n == NULL) { + perror("creating tree node"); + goto fail; + } } free(extra); |