summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/gensquashfs/mkfs.c4
-rw-r--r--include/fstree.h5
-rw-r--r--lib/fstree/fstree_from_dir.c19
3 files changed, 21 insertions, 7 deletions
diff --git a/bin/gensquashfs/mkfs.c b/bin/gensquashfs/mkfs.c
index 6f26d56..4120242 100644
--- a/bin/gensquashfs/mkfs.c
+++ b/bin/gensquashfs/mkfs.c
@@ -191,8 +191,10 @@ int main(int argc, char **argv)
}
if (opt.infile == NULL) {
- if (fstree_from_dir(&sqfs.fs, opt.packdir, opt.dirscan_flags))
+ if (fstree_from_dir(&sqfs.fs, sqfs.fs.root,
+ opt.packdir, opt.dirscan_flags)) {
goto out;
+ }
} else {
if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd))
goto out;
diff --git a/include/fstree.h b/include/fstree.h
index ac92daa..f6ff75f 100644
--- a/include/fstree.h
+++ b/include/fstree.h
@@ -21,6 +21,8 @@ enum {
DIR_SCAN_KEEP_TIME = 0x01,
DIR_SCAN_ONE_FILESYSTEM = 0x02,
+
+ DIR_SCAN_NO_RECURSION = 0x04,
};
#define FSTREE_MODE_HARD_LINK (0)
@@ -241,6 +243,7 @@ int fstree_resolve_hard_link(fstree_t *fs, tree_node_t *node);
Returns 0 on success, prints to stderr on failure.
*/
-int fstree_from_dir(fstree_t *fs, const char *path, unsigned int flags);
+int fstree_from_dir(fstree_t *fs, tree_node_t *root,
+ const char *path, unsigned int flags);
#endif /* FSTREE_H */
diff --git a/lib/fstree/fstree_from_dir.c b/lib/fstree/fstree_from_dir.c
index e61b706..fca916d 100644
--- a/lib/fstree/fstree_from_dir.c
+++ b/lib/fstree/fstree_from_dir.c
@@ -13,9 +13,10 @@
#include <errno.h>
#ifdef _WIN32
-int fstree_from_dir(fstree_t *fs, const char *path, unsigned int flags)
+int fstree_from_dir(fstree_t *fs, tree_node_t *root,
+ const char *path, unsigned int flags)
{
- (void)fs; (void)path; (void)flags;
+ (void)fs; (void)root; (void)path; (void)flags;
fputs("Packing a directory is not supported on Windows.\n", stderr);
return -1;
}
@@ -90,7 +91,7 @@ static int populate_dir(int dir_fd, fstree_t *fs, tree_node_t *root,
free(extra);
extra = NULL;
- if (S_ISDIR(n->mode)) {
+ if (S_ISDIR(n->mode) && !(flags & DIR_SCAN_NO_RECURSION)) {
childfd = openat(dir_fd, n->name, O_DIRECTORY |
O_RDONLY | O_CLOEXEC);
if (childfd < 0) {
@@ -113,11 +114,19 @@ fail:
return -1;
}
-int fstree_from_dir(fstree_t *fs, const char *path, unsigned int flags)
+int fstree_from_dir(fstree_t *fs, tree_node_t *root,
+ const char *path, unsigned int flags)
{
struct stat sb;
int fd;
+ if (!S_ISDIR(root->mode)) {
+ fprintf(stderr,
+ "scanning %s into %s: target is not a directory\n",
+ path, root->name);
+ return -1;
+ }
+
fd = open(path, O_DIRECTORY | O_RDONLY | O_CLOEXEC);
if (fd < 0) {
perror(path);
@@ -130,6 +139,6 @@ int fstree_from_dir(fstree_t *fs, const char *path, unsigned int flags)
return -1;
}
- return populate_dir(fd, fs, fs->root, sb.st_dev, flags);
+ return populate_dir(fd, fs, root, sb.st_dev, flags);
}
#endif