diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-28 15:58:03 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-29 00:26:32 +0200 |
commit | 935d4186952e4e4f544ddb20d8f7e4c2657ecb63 (patch) | |
tree | ffb2e99112bf44236a72a1286f76c54388c37baa /bin/gensquashfs/src | |
parent | 725949af79cbbf359e90c93e88bf184c6114a502 (diff) |
gensquashfs: Remove flag handling from scan_dir
The logic was previously there to allow recursing into directories
that exist in the fstree and the scanned directory, but not create
new directories. Because the dir_tree_iterator_t supports reporting
contents but not directories (and does DFS), we can simply check if
the parent of the directory exists. Under normal DFS, it must exist,
because we created it earlier. If we are skipping the directory
entries, it only exists if it was there earlier and we can skip
entries that have a non-existant parent, retainint the old behavior.
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.c | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c index bd227a3..25a6bd7 100644 --- a/bin/gensquashfs/src/fstree_from_dir.c +++ b/bin/gensquashfs/src/fstree_from_dir.c @@ -41,12 +41,13 @@ static void discard_node(tree_node_t *root, tree_node_t *n) } static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir, - scan_node_callback cb, void *user, unsigned int flags) + scan_node_callback cb, void *user) { for (;;) { dir_entry_t *ent = NULL; tree_node_t *n = NULL; char *extra = NULL; + struct stat sb; int ret = dir->next(dir, &ent); if (ret > 0) @@ -56,6 +57,14 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir, return -1; } + n = fstree_get_node_by_path(fs, root, ent->name, false, true); + if (n == NULL) { + if (S_ISDIR(ent->mode)) + dir_tree_iterator_skip(dir); + free(ent); + continue; + } + if (S_ISLNK(ent->mode)) { ret = dir->read_link(dir, &extra); if (ret) { @@ -65,39 +74,22 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir, } } - if (S_ISDIR(ent->mode) && (flags & DIR_SCAN_NO_DIR)) { - n = fstree_get_node_by_path(fs, root, ent->name, - false, false); - if (n == NULL) { - free(ent); - dir_tree_iterator_skip(dir); - continue; - } + memset(&sb, 0, sizeof(sb)); + sb.st_uid = ent->uid; + sb.st_gid = ent->gid; + sb.st_mode = ent->mode; + sb.st_mtime = clamp_timestamp(ent->mtime); - ret = 0; - } else { - struct stat sb; - - memset(&sb, 0, sizeof(sb)); - sb.st_uid = ent->uid; - sb.st_gid = ent->gid; - sb.st_mode = ent->mode; - sb.st_mtime = clamp_timestamp(ent->mtime); - - n = fstree_add_generic_at(fs, root, ent->name, - &sb, extra); - if (n == NULL) { - perror("creating tree node"); - free(extra); - free(ent); - return -1; - } + n = fstree_add_generic_at(fs, root, ent->name, &sb, extra); + free(extra); + free(ent); - ret = (cb == NULL) ? 0 : cb(user, fs, n); + if (n == NULL) { + perror("creating tree node"); + return -1; } - free(ent); - free(extra); + ret = (cb == NULL) ? 0 : cb(user, fs, n); if (ret < 0) return -1; @@ -120,14 +112,14 @@ int fstree_from_dir(fstree_t *fs, tree_node_t *root, const char *path, int ret; memset(&cfg, 0, sizeof(cfg)); - cfg.flags = flags & ~(DIR_SCAN_NO_DIR); + cfg.flags = flags; cfg.def_mtime = fs->defaults.mtime; dir = dir_tree_iterator_create(path, &cfg); if (dir == NULL) return -1; - ret = scan_dir(fs, root, dir, cb, user, flags); + ret = scan_dir(fs, root, dir, cb, user); sqfs_drop(dir); return ret; } |