aboutsummaryrefslogtreecommitdiff
path: root/bin/gensquashfs/src
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-28 12:22:18 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-29 00:26:32 +0200
commit11e36726f61e8615bb873c2d322d85dafcd73e7b (patch)
treec186f6411409bc735342643b44667a14895d6f6e /bin/gensquashfs/src
parentea8ed35e8665be75923bb483c377421d24ae2faf (diff)
Move type based filtering to libutil dir_tree_iterator_t
Limited unit testing for the flags is added, particularly the abillity to recurse into sub-directories, but not report the parents as individual entries. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs/src')
-rw-r--r--bin/gensquashfs/src/fstree_from_dir.c45
-rw-r--r--bin/gensquashfs/src/mkfs.h16
2 files changed, 6 insertions, 55 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c
index 9241428..4c6a828 100644
--- a/bin/gensquashfs/src/fstree_from_dir.c
+++ b/bin/gensquashfs/src/fstree_from_dir.c
@@ -12,32 +12,6 @@
#include <string.h>
#include <errno.h>
-static bool should_skip(const dir_iterator_t *dir, const dir_entry_t *ent,
- unsigned int flags)
-{
- if ((flags & DIR_SCAN_ONE_FILESYSTEM) && ent->dev != dir->dev)
- return true;
-
- switch (ent->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;
-}
-
static sqfs_u32 clamp_timestamp(sqfs_s64 ts)
{
if (ts < 0)
@@ -82,11 +56,6 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
return -1;
}
- if (should_skip(dir, ent, flags)) {
- free(ent);
- continue;
- }
-
if (S_ISLNK(ent->mode)) {
ret = dir->read_link(dir, &extra);
if (ret) {
@@ -96,9 +65,6 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
}
}
- if (!(flags & DIR_SCAN_KEEP_TIME))
- ent->mtime = fs->defaults.mtime;
-
if (S_ISDIR(ent->mode) && (flags & DIR_SCAN_NO_DIR)) {
n = fstree_get_node_by_path(fs, root, ent->name,
false, false);
@@ -140,11 +106,7 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
if (S_ISDIR(n->mode))
dir_tree_iterator_skip(dir);
discard_node(n->parent, n);
- continue;
}
-
- if ((flags & DIR_SCAN_NO_RECURSION) && S_ISDIR(n->mode))
- dir_tree_iterator_skip(dir);
}
return 0;
@@ -156,6 +118,7 @@ int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
unsigned int flags)
{
dir_iterator_t *dir;
+ dir_tree_cfg_t cfg;
size_t plen, slen;
char *temp = NULL;
int ret;
@@ -186,7 +149,11 @@ int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
path = temp;
}
- dir = dir_tree_iterator_create(path);
+ memset(&cfg, 0, sizeof(cfg));
+ cfg.flags = flags & ~(DIR_SCAN_NO_DIR);
+ cfg.def_mtime = fs->defaults.mtime;
+
+ dir = dir_tree_iterator_create(path, &cfg);
free(temp);
if (dir == NULL)
return -1;
diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h
index 28bcfde..a58365d 100644
--- a/bin/gensquashfs/src/mkfs.h
+++ b/bin/gensquashfs/src/mkfs.h
@@ -42,22 +42,6 @@
#include <errno.h>
#include <ctype.h>
-enum {
- DIR_SCAN_KEEP_TIME = 0x01,
-
- 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,
-};
-
/*
Optionally used by fstree_from_dir and fstree_from_subdir to
execute custom actions for each discovered node.