aboutsummaryrefslogtreecommitdiff
path: root/bin/gensquashfs/src
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-28 19:36:56 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-29 00:26:32 +0200
commit2285036e10863aba48dc6eed3c1a791118d11956 (patch)
treed94808261eb23df4c25db3c6de6dd45df2e692c7 /bin/gensquashfs/src
parent46b01473eee7301cb7b49533af16abe0ee15c286 (diff)
gensquashfs: Dismantle the scan_dir wrapper
Create the directory iterator externally and pass it to fstree_from_dir. The unit test is also removed, because the heavy lifting is now done outside the function. 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.c22
-rw-r--r--bin/gensquashfs/src/fstree_from_file.c32
-rw-r--r--bin/gensquashfs/src/mkfs.c18
-rw-r--r--bin/gensquashfs/src/mkfs.h5
4 files changed, 37 insertions, 40 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c
index 22493c5..b2d27f1 100644
--- a/bin/gensquashfs/src/fstree_from_dir.c
+++ b/bin/gensquashfs/src/fstree_from_dir.c
@@ -21,7 +21,7 @@ static sqfs_u32 clamp_timestamp(sqfs_s64 ts)
return ts;
}
-static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
+int fstree_from_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
scan_node_callback cb, void *user)
{
for (;;) {
@@ -84,23 +84,3 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
return 0;
}
-
-int fstree_from_dir(fstree_t *fs, tree_node_t *root, const char *path,
- scan_node_callback cb, void *user, unsigned int flags)
-{
- dir_iterator_t *dir;
- dir_tree_cfg_t cfg;
- int ret;
-
- memset(&cfg, 0, sizeof(cfg));
- 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);
- sqfs_drop(dir);
- return ret;
-}
diff --git a/bin/gensquashfs/src/fstree_from_file.c b/bin/gensquashfs/src/fstree_from_file.c
index e75c819..77f9ebd 100644
--- a/bin/gensquashfs/src/fstree_from_file.c
+++ b/bin/gensquashfs/src/fstree_from_file.c
@@ -245,9 +245,11 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num,
const char *extra)
{
unsigned int scan_flags = 0, all_flags;
+ dir_iterator_t *dir = NULL;
struct glob_context ctx;
bool first_clear_flag;
size_t i, count, len;
+ dir_tree_cfg_t cfg;
tree_node_t *root;
int ret;
@@ -362,15 +364,13 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num,
extra = NULL;
/* do the scan */
+ memset(&cfg, 0, sizeof(cfg));
+ cfg.flags = scan_flags;
+ cfg.def_mtime = fs->defaults.mtime;
+
if (basepath == NULL) {
- if (extra == NULL) {
- ret = fstree_from_dir(fs, root, ".", glob_node_callback,
- &ctx, scan_flags);
- } else {
- ret = fstree_from_dir(fs, root, extra,
- glob_node_callback,
- &ctx, scan_flags);
- }
+ dir = dir_tree_iterator_create(extra == NULL ? "." : extra,
+ &cfg);
} else {
size_t plen = strlen(basepath);
size_t slen = strlen(extra);
@@ -379,18 +379,24 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num,
if (temp == NULL) {
fprintf(stderr, "%s: " PRI_SZ ": allocation failure.\n",
filename, line_num);
- ret = -1;
} else {
memcpy(temp, basepath, plen);
temp[plen] = '/';
memcpy(temp + plen + 1, extra, slen);
temp[plen + 1 + slen] = '\0';
- ret = fstree_from_dir(fs, root, temp,
- glob_node_callback, &ctx,
- scan_flags);
- free(temp);
+ dir = dir_tree_iterator_create(temp, &cfg);
}
+
+ free(temp);
+ }
+
+ if (dir != NULL) {
+ ret = fstree_from_dir(fs, root, dir,
+ glob_node_callback, &ctx);
+ sqfs_drop(dir);
+ } else {
+ ret = -1;
}
free(ctx.name_pattern);
diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c
index 683077b..f2973b6 100644
--- a/bin/gensquashfs/src/mkfs.c
+++ b/bin/gensquashfs/src/mkfs.c
@@ -166,10 +166,22 @@ int main(int argc, char **argv)
}
if (opt.infile == NULL) {
- if (fstree_from_dir(&sqfs.fs, sqfs.fs.root, opt.packdir,
- NULL, NULL, opt.dirscan_flags)) {
+ dir_iterator_t *dir = NULL;
+ dir_tree_cfg_t cfg;
+ int ret;
+
+ memset(&cfg, 0, sizeof(cfg));
+ cfg.flags = opt.dirscan_flags;
+ cfg.def_mtime = sqfs.fs.defaults.mtime;
+
+ dir = dir_tree_iterator_create(opt.packdir, &cfg);
+ if (dir == NULL)
+ goto out;
+
+ ret = fstree_from_dir(&sqfs.fs, sqfs.fs.root, dir, NULL, NULL);
+ sqfs_drop(dir);
+ if (ret != 0)
goto out;
- }
} else {
if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd))
goto out;
diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h
index 9064a75..6923164 100644
--- a/bin/gensquashfs/src/mkfs.h
+++ b/bin/gensquashfs/src/mkfs.h
@@ -130,9 +130,8 @@ int fstree_from_file_stream(fstree_t *fs, istream_t *file,
Returns 0 on success, prints to stderr on failure.
*/
-int fstree_from_dir(fstree_t *fs, tree_node_t *root,
- const char *path, scan_node_callback cb, void *user,
- unsigned int flags);
+int fstree_from_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
+ scan_node_callback cb, void *user);
int fstree_sort_files(fstree_t *fs, istream_t *sortfile);