diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-28 17:06:06 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-29 00:26:32 +0200 |
commit | 46b01473eee7301cb7b49533af16abe0ee15c286 (patch) | |
tree | 38b16209b29f6ac95e537ea411db1174242925b5 /bin/gensquashfs/src/fstree_from_dir.c | |
parent | 935d4186952e4e4f544ddb20d8f7e4c2657ecb63 (diff) |
gensquashfs: Move the scan_dir callback before creating the node
This way, we can remove the discard_node function and simplify the
scan_dir code further.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs/src/fstree_from_dir.c')
-rw-r--r-- | bin/gensquashfs/src/fstree_from_dir.c | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c index 25a6bd7..22493c5 100644 --- a/bin/gensquashfs/src/fstree_from_dir.c +++ b/bin/gensquashfs/src/fstree_from_dir.c @@ -21,25 +21,6 @@ static sqfs_u32 clamp_timestamp(sqfs_s64 ts) return ts; } -static void discard_node(tree_node_t *root, tree_node_t *n) -{ - tree_node_t *it; - - if (n == root->data.children) { - root->data.children = n->next; - } else { - it = root->data.children; - - while (it != NULL && it->next != n) - it = it->next; - - if (it != NULL) - it->next = n->next; - } - - free(n); -} - static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir, scan_node_callback cb, void *user) { @@ -58,7 +39,18 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir, } n = fstree_get_node_by_path(fs, root, ent->name, false, true); - if (n == NULL) { + if (n == NULL) + ret = 1; + + if (ret == 0 && cb != NULL) + ret = cb(user, root, ent); + + if (ret < 0) { + free(ent); + return -1; + } + + if (ret > 0) { if (S_ISDIR(ent->mode)) dir_tree_iterator_skip(dir); free(ent); @@ -88,17 +80,6 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir, perror("creating tree node"); return -1; } - - ret = (cb == NULL) ? 0 : cb(user, fs, n); - - if (ret < 0) - return -1; - - if (ret > 0) { - if (S_ISDIR(n->mode)) - dir_tree_iterator_skip(dir); - discard_node(n->parent, n); - } } return 0; |