aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/gensquashfs/src/fstree_from_dir.c42
-rw-r--r--bin/gensquashfs/src/fstree_from_file.c28
-rw-r--r--bin/gensquashfs/src/mkfs.h13
3 files changed, 29 insertions, 54 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c
index 4c6a828..bd227a3 100644
--- a/bin/gensquashfs/src/fstree_from_dir.c
+++ b/bin/gensquashfs/src/fstree_from_dir.c
@@ -112,49 +112,18 @@ static int scan_dir(fstree_t *fs, tree_node_t *root, dir_iterator_t *dir,
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)
+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;
- size_t plen, slen;
- char *temp = NULL;
int ret;
- if (!S_ISDIR(root->mode)) {
- fprintf(stderr,
- "scanning %s/%s into %s: target is not a directory\n",
- path, subdir == NULL ? "" : subdir, root->name);
- return -1;
- }
-
- 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;
- }
-
memset(&cfg, 0, sizeof(cfg));
cfg.flags = flags & ~(DIR_SCAN_NO_DIR);
cfg.def_mtime = fs->defaults.mtime;
dir = dir_tree_iterator_create(path, &cfg);
- free(temp);
if (dir == NULL)
return -1;
@@ -162,10 +131,3 @@ int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
sqfs_drop(dir);
return ret;
}
-
-int fstree_from_dir(fstree_t *fs, tree_node_t *root,
- const char *path, scan_node_callback cb,
- void *user, unsigned int flags)
-{
- return fstree_from_subdir(fs, root, path, NULL, cb, user, flags);
-}
diff --git a/bin/gensquashfs/src/fstree_from_file.c b/bin/gensquashfs/src/fstree_from_file.c
index d051737..34fcf83 100644
--- a/bin/gensquashfs/src/fstree_from_file.c
+++ b/bin/gensquashfs/src/fstree_from_file.c
@@ -232,6 +232,12 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num,
return -1;
}
+ if (!S_ISDIR(root->mode)) {
+ fprintf(stderr, "%s: " PRI_SZ ": %s is not a directoy!\n",
+ filename, line_num, path);
+ return -1;
+ }
+
/* process options */
first_clear_flag = true;
@@ -333,9 +339,25 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num,
&ctx, scan_flags);
}
} else {
- ret = fstree_from_subdir(fs, root, basepath, extra,
- glob_node_callback, &ctx,
- scan_flags);
+ size_t plen = strlen(basepath);
+ size_t slen = strlen(extra);
+ char *temp = calloc(1, plen + 1 + slen + 1);
+
+ 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);
+ }
}
free(ctx.name_pattern);
diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h
index a58365d..5bcdd16 100644
--- a/bin/gensquashfs/src/mkfs.h
+++ b/bin/gensquashfs/src/mkfs.h
@@ -43,8 +43,8 @@
#include <ctype.h>
/*
- Optionally used by fstree_from_dir and fstree_from_subdir to
- execute custom actions for each discovered node.
+ Optionally used by fstree_from_dir to execute custom actions for
+ each discovered node.
If it returns a value > 0, the new node is discarded, if < 0, scanning is
aborted and returns a failure status.
@@ -133,15 +133,6 @@ int fstree_from_dir(fstree_t *fs, tree_node_t *root,
const char *path, scan_node_callback cb, void *user,
unsigned int flags);
-/*
- Same as fstree_from_dir, but scans a sub-directory inside the specified path.
-
- Returns 0 on success, prints to stderr on failure.
- */
-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);
-
int fstree_sort_files(fstree_t *fs, istream_t *sortfile);
#endif /* MKFS_H */