diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-10 17:02:51 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-12 20:41:34 +0200 |
commit | ec289120f5a8edef86037945ad3ab30f24534cbd (patch) | |
tree | 50bd684de05dafed3a0ddbc203f1244208eed93c /bin/gensquashfs | |
parent | 0bd3afbf487c15221f9d4cfbc19a07e3c4b87587 (diff) |
gensquashfs: merge some of the Windows and Unix entry filtering code
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs')
-rw-r--r-- | bin/gensquashfs/src/fstree_from_dir.c | 75 |
1 files changed, 29 insertions, 46 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c index 804f64c..137900d 100644 --- a/bin/gensquashfs/src/fstree_from_dir.c +++ b/bin/gensquashfs/src/fstree_from_dir.c @@ -12,6 +12,31 @@ #include <string.h> #include <errno.h> +static bool should_skip(const char *name, sqfs_u16 mode, unsigned int flags) +{ + if (!strcmp(name, "..") || !strcmp(name, ".")) + return true; + + switch (mode & S_IFMT) { + case S_IFSOCK: + return (flags & DIR_SCAN_NO_SOCK) != 0; + case S_IFLNK: + return (flags & DIR_SCAN_NO_SLINK) != 0; + case S_IFREG: + return (flags & DIR_SCAN_NO_FILE) != 0; + case S_IFBLK: + return (flags & DIR_SCAN_NO_BLK) != 0; + case S_IFCHR: + return (flags & DIR_SCAN_NO_CHR) != 0; + case S_IFIFO: + return (flags & DIR_SCAN_NO_FIFO) != 0; + default: + break; + } + + return false; +} + #if defined(_WIN32) || defined(__WINDOWS__) static int add_node(fstree_t *fs, tree_node_t *root, scan_node_callback cb, void *user, @@ -21,21 +46,8 @@ static int add_node(fstree_t *fs, tree_node_t *root, size_t length = strlen(entry->name); tree_node_t *n; - if (entry->name[0] == '.') { - if (length == 1) - return 0; - - if (entry->name[1] == '.' && length == 2) - return 0; - } - - if (S_ISDIR(entry->mode)) { - if (flags & DIR_SCAN_NO_DIR) - return 0; - } else { - if (flags & DIR_SCAN_NO_FILE) - return 0; - } + if (should_skip(entry->name, entry->mode, flags)) + return 0; n = calloc(1, sizeof(*n) + length + 1); if (n == NULL) { @@ -212,42 +224,13 @@ static int populate_dir(int dir_fd, fstree_t *fs, tree_node_t *root, break; } - if (!strcmp(ent->d_name, "..") || !strcmp(ent->d_name, ".")) - continue; - if (fstatat(dir_fd, ent->d_name, &sb, AT_SYMLINK_NOFOLLOW)) { perror(ent->d_name); 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 (should_skip(ent->d_name, sb.st_mode, flags)) + continue; if ((flags & DIR_SCAN_ONE_FILESYSTEM) && sb.st_dev != devstart) continue; |