diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-10-24 14:45:36 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-10-24 15:57:18 +0200 |
commit | 3c70940f4c1b8534e1ef547e09050d33b8187122 (patch) | |
tree | b920e94c70f0317e3723c50f2c8e0138828e9f2f | |
parent | d17f308b24a332d1767888e086ece9a2e71a891d (diff) |
Cleanup: gensquashfs: merge glob scan_directory & fstree_from_dir
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | bin/gensquashfs/Makemodule.am | 6 | ||||
-rw-r--r-- | bin/gensquashfs/src/fstree_from_dir.c | 44 | ||||
-rw-r--r-- | bin/gensquashfs/src/glob.c | 7 | ||||
-rw-r--r-- | bin/gensquashfs/src/mkfs.c | 2 | ||||
-rw-r--r-- | bin/gensquashfs/src/mkfs.h | 10 |
5 files changed, 8 insertions, 61 deletions
diff --git a/bin/gensquashfs/Makemodule.am b/bin/gensquashfs/Makemodule.am index f983ccf..a5bf78f 100644 --- a/bin/gensquashfs/Makemodule.am +++ b/bin/gensquashfs/Makemodule.am @@ -2,7 +2,6 @@ gensquashfs_SOURCES = bin/gensquashfs/src/mkfs.c bin/gensquashfs/src/mkfs.h \ bin/gensquashfs/src/options.c bin/gensquashfs/src/selinux.c \ bin/gensquashfs/src/apply_xattr.c bin/gensquashfs/src/filemap_xattr.c\ bin/gensquashfs/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ bin/gensquashfs/src/sort_by_file.c bin/gensquashfs/src/glob.c gensquashfs_LDADD = libcommon.a libio.a libsquashfs.la libfstree.a gensquashfs_LDADD += libutil.a libcompat.a $(LZO_LIBS) $(PTHREAD_LIBS) @@ -30,7 +29,6 @@ test_filemap_xattr_LDADD += libcommon.a libcompat.a test_fstree_from_file_SOURCES = bin/gensquashfs/test/fstree_from_file.c \ bin/gensquashfs/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ bin/gensquashfs/src/glob.c \ bin/gensquashfs/src/mkfs.h test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) @@ -40,7 +38,6 @@ test_fstree_from_file_LDADD = libio.a libsquashfs.la libcommon.a libfstree.a \ test_fstree_from_file2_SOURCES = bin/gensquashfs/test/fstree_from_file2.c \ bin/gensquashfs/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ bin/gensquashfs/src/glob.c \ bin/gensquashfs/src/mkfs.h test_fstree_from_file2_CPPFLAGS = $(AM_CPPFLAGS) @@ -50,7 +47,6 @@ test_fstree_from_file2_LDADD = libio.a libsquashfs.la libcommon.a libfstree.a \ test_fstree_glob1_SOURCES = bin/gensquashfs/test/fstree_glob1.c \ bin/gensquashfs/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ bin/gensquashfs/src/glob.c \ bin/gensquashfs/src/mkfs.h test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs/src @@ -60,7 +56,6 @@ test_fstree_glob1_LDADD = libio.a libsquashfs.la libcommon.a libfstree.a \ test_sort_file_SOURCES = bin/gensquashfs/test/sort_file.c \ bin/gensquashfs/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ bin/gensquashfs/src/sort_by_file.c \ bin/gensquashfs/src/glob.c \ bin/gensquashfs/src/mkfs.h @@ -70,7 +65,6 @@ test_sort_file_LDADD = libio.a libsquashfs.la libcommon.a libfstree.a \ fstree_fuzz_SOURCES = bin/gensquashfs/test/fstree_fuzz.c \ bin/gensquashfs/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ bin/gensquashfs/src/glob.c \ bin/gensquashfs/src/mkfs.h fstree_fuzz_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs/src diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c deleted file mode 100644 index 40b4061..0000000 --- a/bin/gensquashfs/src/fstree_from_dir.c +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_from_dir.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "mkfs.h" - -int fstree_from_dir(fstree_t *fs, sqfs_dir_iterator_t *dir) -{ - for (;;) { - sqfs_dir_entry_t *ent = NULL; - tree_node_t *n = NULL; - char *extra = NULL; - - int ret = dir->next(dir, &ent); - if (ret > 0) - break; - if (ret < 0) { - sqfs_perror("readdir", NULL, ret); - return -1; - } - - if (S_ISLNK(ent->mode)) { - ret = dir->read_link(dir, &extra); - if (ret) { - sqfs_perror("readlink", ent->name, ret); - free(ent); - return -1; - } - } - - n = fstree_add_generic(fs, ent, extra); - free(extra); - free(ent); - - if (n == NULL) { - perror("creating tree node"); - return -1; - } - } - - return 0; -} diff --git a/bin/gensquashfs/src/glob.c b/bin/gensquashfs/src/glob.c index bc6edee..73f078b 100644 --- a/bin/gensquashfs/src/glob.c +++ b/bin/gensquashfs/src/glob.c @@ -64,8 +64,8 @@ static bool set_scan_flag(const char *arg, dir_tree_cfg_t *cfg) return false; } -static int scan_directory(fstree_t *fs, sqfs_dir_iterator_t *dir, - size_t prefix_len, const char *file_prefix) +int scan_directory(fstree_t *fs, sqfs_dir_iterator_t *dir, + size_t prefix_len, const char *file_prefix) { for (;;) { sqfs_dir_entry_t *ent = NULL; @@ -96,7 +96,8 @@ static int scan_directory(fstree_t *fs, sqfs_dir_iterator_t *dir, free(ent); return -1; } - } else if (S_ISREG(ent->mode)) { + } else if (S_ISREG(ent->mode) && + (prefix_len > 0 || file_prefix != NULL)) { const char *src; /* skip the prefix, get the name actually diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c index 320e250..488d015 100644 --- a/bin/gensquashfs/src/mkfs.c +++ b/bin/gensquashfs/src/mkfs.c @@ -141,7 +141,7 @@ int main(int argc, char **argv) if (dir == NULL) goto out; - ret = fstree_from_dir(&sqfs.fs, dir); + ret = scan_directory(&sqfs.fs, dir, 0, NULL); sqfs_drop(dir); if (ret != 0) goto out; diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h index 437198b..a762966 100644 --- a/bin/gensquashfs/src/mkfs.h +++ b/bin/gensquashfs/src/mkfs.h @@ -104,15 +104,11 @@ int fstree_from_file(fstree_t *fs, const char *filename, const options_t *opt); int fstree_from_file_stream(fstree_t *fs, sqfs_istream_t *file, const options_t *opt); -/* - Recursively scan a directory to build a file system tree. - - Returns 0 on success, prints to stderr on failure. - */ -int fstree_from_dir(fstree_t *fs, sqfs_dir_iterator_t *dir); - int fstree_sort_files(fstree_t *fs, sqfs_istream_t *sortfile); +int scan_directory(fstree_t *fs, sqfs_dir_iterator_t *dir, + size_t prefix_len, const char *file_prefix); + int glob_files(fstree_t *fs, const char *filename, size_t line_num, const sqfs_dir_entry_t *ent, const char *basepath, unsigned int glob_flags, |