summaryrefslogtreecommitdiff
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
parent76c04748d7b3fec12ed81d464a1e6121181dec99 (diff)
fstree_from_dir: add filtering flags to skip certain inode types
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/fstree.h8
-rw-r--r--lib/fstree/fstree_from_dir.c46
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);