aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-10 18:35:57 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-12 20:41:34 +0200
commit013fcc9475968675587828bfc9d633e181263c0c (patch)
treec8f9abfa635e5cad9cf3b154d0c6840cfea2b625 /bin
parent426d2d521ccd44ff8c41d2577fbace6f1726dbd2 (diff)
Merge Windows and Unix implementations of fstree_from_subdir
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin')
-rw-r--r--bin/gensquashfs/src/fstree_from_dir.c66
1 files changed, 6 insertions, 60 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c
index 8923603..c097304 100644
--- a/bin/gensquashfs/src/fstree_from_dir.c
+++ b/bin/gensquashfs/src/fstree_from_dir.c
@@ -84,10 +84,8 @@ static int add_node(fstree_t *fs, tree_node_t *root,
return 0;
}
-static int scan_dir(fstree_t *fs, tree_node_t *root,
- const char *path,
- scan_node_callback cb, void *user,
- unsigned int flags)
+static int scan_dir(fstree_t *fs, tree_node_t *root, const char *path,
+ scan_node_callback cb, void *user, unsigned int flags)
{
dir_iterator_t *it = dir_iterator_create(path);
@@ -118,58 +116,6 @@ static int scan_dir(fstree_t *fs, tree_node_t *root,
sqfs_drop(it);
return 0;
}
-
-int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
- const char *path, const char *subdir,
- scan_node_callback cb, void *user,
- unsigned int flags)
-{
- size_t plen, slen;
- char *temp = NULL;
- tree_node_t *n;
-
- plen = strlen(path);
- slen = subdir == NULL ? 0 : strlen(subdir);
-
- if (slen > 0) {
- temp = calloc(1, plen + 1 + slen + 1);
- if (temp == NULL) {
- fprintf(stderr, "%s/%s: allocation failure.\n",
- path, subdir);
- return -1;
- }
-
- memcpy(temp, path, plen);
- temp[plen] = '/';
- memcpy(temp + plen + 1, subdir, slen);
- temp[plen + 1 + slen] = '\0';
-
- path = temp;
- }
-
- if (scan_dir(fs, root, path, cb, user, flags))
- goto fail;
-
- if (flags & DIR_SCAN_NO_RECURSION) {
- free(temp);
- return 0;
- }
-
- for (n = root->data.dir.children; n != NULL; n = n->next) {
- if (!S_ISDIR(n->mode))
- continue;
-
- if (fstree_from_subdir(fs, n, path, n->name, cb, user, flags))
- goto fail;
- }
-
- free(temp);
- return 0;
-fail:
- free(temp);
- return -1;
-
-}
#else
static void discard_node(tree_node_t *root, tree_node_t *n)
{
@@ -220,8 +166,8 @@ static char *read_link(const struct stat *sb, int dir_fd, const char *name)
return out;
}
-static int populate_dir(const char *path, fstree_t *fs, tree_node_t *root,
- scan_node_callback cb, void *user, unsigned int flags)
+static int scan_dir(fstree_t *fs, tree_node_t *root, const char *path,
+ scan_node_callback cb, void *user, unsigned int flags)
{
char *extra = NULL;
dev_t devstart = 0;
@@ -315,6 +261,7 @@ fail:
free(extra);
return -1;
}
+#endif
int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
const char *path, const char *subdir,
@@ -351,7 +298,7 @@ int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
path = temp;
}
- if (populate_dir(path, fs, root, cb, user, flags))
+ if (scan_dir(fs, root, path, cb, user, flags))
goto fail;
if (flags & DIR_SCAN_NO_RECURSION) {
@@ -373,7 +320,6 @@ fail:
free(temp);
return -1;
}
-#endif
int fstree_from_dir(fstree_t *fs, tree_node_t *root,
const char *path, scan_node_callback cb,