aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-28 00:50:31 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-29 00:26:32 +0200
commitea8ed35e8665be75923bb483c377421d24ae2faf (patch)
tree8f0eff30da56d1bb5143dd72e32054cd2c405766
parent1b832b6dfb8d9da2b94f07ccc95c03614b378786 (diff)
gensquashfs: use stacked tree iterator in fstree_from_dir
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--bin/gensquashfs/src/fstree_from_dir.c30
-rw-r--r--bin/gensquashfs/src/mkfs.h2
-rw-r--r--include/fstree.h4
-rw-r--r--lib/fstree/src/add_by_path.c11
4 files changed, 23 insertions, 24 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c
index 6200ea3..9241428 100644
--- a/bin/gensquashfs/src/fstree_from_dir.c
+++ b/bin/gensquashfs/src/fstree_from_dir.c
@@ -15,9 +15,6 @@
static bool should_skip(const dir_iterator_t *dir, const dir_entry_t *ent,
unsigned int flags)
{
- if (!strcmp(ent->name, "..") || !strcmp(ent->name, "."))
- return true;
-
if ((flags & DIR_SCAN_ONE_FILESYSTEM) && ent->dev != dir->dev)
return true;
@@ -107,6 +104,7 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
false, false);
if (n == NULL) {
free(ent);
+ dir_tree_iterator_skip(dir);
continue;
}
@@ -120,8 +118,8 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
sb.st_mode = ent->mode;
sb.st_mtime = clamp_timestamp(ent->mtime);
- n = fstree_mknode(root, ent->name,
- strlen(ent->name), extra, &sb);
+ n = fstree_add_generic_at(fs, root, ent->name,
+ &sb, extra);
if (n == NULL) {
perror("creating tree node");
free(extra);
@@ -139,24 +137,14 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
return -1;
if (ret > 0) {
- discard_node(root, n);
+ 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_iterator_t *sub;
-
- ret = dir->open_subdir(dir, &sub);
- if (ret != 0) {
- sqfs_perror(n->name, "opening directory", ret);
- return -1;
- }
-
- ret = scan_dir(fs, n, sub, cb, user, flags);
- sqfs_drop(sub);
- if (ret)
- return -1;
- }
+ if ((flags & DIR_SCAN_NO_RECURSION) && S_ISDIR(n->mode))
+ dir_tree_iterator_skip(dir);
}
return 0;
@@ -198,7 +186,7 @@ int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
path = temp;
}
- dir = dir_iterator_create(path);
+ dir = dir_tree_iterator_create(path);
free(temp);
if (dir == NULL)
return -1;
diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h
index 6b69465..28bcfde 100644
--- a/bin/gensquashfs/src/mkfs.h
+++ b/bin/gensquashfs/src/mkfs.h
@@ -12,7 +12,7 @@
#include "common.h"
#include "fstree.h"
-#include "util/dir_iterator.h"
+#include "util/dir_tree_iterator.h"
#include "util/util.h"
#include "io/file.h"
diff --git a/include/fstree.h b/include/fstree.h
index 96ddf8f..ccd1bcc 100644
--- a/include/fstree.h
+++ b/include/fstree.h
@@ -160,6 +160,10 @@ tree_node_t *fstree_mknode(tree_node_t *parent, const char *name,
tree_node_t *fstree_add_generic(fstree_t *fs, const char *path,
const struct stat *sb, const char *extra);
+tree_node_t *fstree_add_generic_at(fstree_t *fs, tree_node_t *root,
+ const char *path, const struct stat *sb,
+ const char *extra);
+
/*
This function performs all the necessary post processing steps on the file
system tree, i.e. recursively sorting all directory entries by name,
diff --git a/lib/fstree/src/add_by_path.c b/lib/fstree/src/add_by_path.c
index 344b586..f204836 100644
--- a/lib/fstree/src/add_by_path.c
+++ b/lib/fstree/src/add_by_path.c
@@ -15,16 +15,23 @@
tree_node_t *fstree_add_generic(fstree_t *fs, const char *path,
const struct stat *sb, const char *extra)
{
+ return fstree_add_generic_at(fs, fs->root, path, sb, extra);
+}
+
+tree_node_t *fstree_add_generic_at(fstree_t *fs, tree_node_t *root,
+ const char *path, const struct stat *sb,
+ const char *extra)
+{
tree_node_t *child, *parent;
const char *name;
if (*path == '\0') {
- child = fs->root;
+ child = root;
assert(child != NULL);
goto out;
}
- parent = fstree_get_node_by_path(fs, fs->root, path, true, true);
+ parent = fstree_get_node_by_path(fs, root, path, true, true);
if (parent == NULL)
return NULL;