summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-01-21 21:49:28 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-02-18 23:50:46 +0100
commitb3051223fcafc954767058811d279f5b6941a9ba (patch)
tree4eb1e30d423823f300112e45ac37cfc16a4e3f0d /lib
parent76c04748d7b3fec12ed81d464a1e6121181dec99 (diff)
fstree_from_dir: add filtering flags to skip certain inode types
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/fstree/fstree_from_dir.c46
1 files changed, 41 insertions, 5 deletions
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);