aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/gensquashfs/src/fstree_from_dir.c2
-rw-r--r--include/io/dir_iterator.h21
-rw-r--r--lib/io/src/dir_tree_iterator.c15
-rw-r--r--lib/io/src/unix/dir_iterator.c7
-rw-r--r--lib/io/src/win32/dir_iterator.c7
-rw-r--r--lib/io/test/dir_tree_iterator.c4
6 files changed, 36 insertions, 20 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c
index 6709368..6c37ee8 100644
--- a/bin/gensquashfs/src/fstree_from_dir.c
+++ b/bin/gensquashfs/src/fstree_from_dir.c
@@ -41,7 +41,7 @@ int fstree_from_dir(fstree_t *fs, dir_iterator_t *dir)
false, true);
if (n == NULL) {
if (S_ISDIR(ent->mode))
- dir_tree_iterator_skip(dir);
+ dir->ignore_subdir(dir);
free(ent);
continue;
}
diff --git a/include/io/dir_iterator.h b/include/io/dir_iterator.h
index 74027f5..60c3796 100644
--- a/include/io/dir_iterator.h
+++ b/include/io/dir_iterator.h
@@ -125,6 +125,17 @@ typedef struct dir_iterator_t {
*/
int (*open_subdir)(struct dir_iterator_t *it,
struct dir_iterator_t **out);
+
+ /**
+ * @brief Skip a sub-hierarchy on a stacked iterator
+ *
+ * If an iterator would ordinarily recurse into a sub-directory,
+ * tell it to skip those entries. On simple, flag iterators like the
+ * one returned by @ref dir_iterator_create, this has no effect.
+ *
+ * @param it A pointer to the iterator itself.
+ */
+ void (*ignore_subdir)(struct dir_iterator_t *it);
} dir_iterator_t;
enum {
@@ -215,16 +226,6 @@ SQFS_INTERNAL
dir_iterator_t *dir_tree_iterator_create(const char *path,
const dir_tree_cfg_t *cfg);
-/**
- * @brief Skip a sub-hierarchy on a stacked iterator
- *
- * For an iterator returned by @ref dir_tree_iterator_create, if the last entry
- * was a directory, do not recurse, but instead skip across the netire sub-tree.
- *
- * @param it A pointer to an iterator returned by @ref dir_tree_iterator_create
- */
-SQFS_INTERNAL void dir_tree_iterator_skip(dir_iterator_t *it);
-
#ifdef __cplusplus
}
#endif
diff --git a/lib/io/src/dir_tree_iterator.c b/lib/io/src/dir_tree_iterator.c
index 85b1c9f..604efd5 100644
--- a/lib/io/src/dir_tree_iterator.c
+++ b/lib/io/src/dir_tree_iterator.c
@@ -265,6 +265,13 @@ static int open_subdir(dir_iterator_t *base, dir_iterator_t **out)
return it->top->dir->open_subdir(it->top->dir, out);
}
+static void ignore_subdir(dir_iterator_t *base)
+{
+ dir_tree_iterator_t *it = (dir_tree_iterator_t *)base;
+
+ pop(it);
+}
+
dir_iterator_t *dir_tree_iterator_create(const char *path,
const dir_tree_cfg_t *cfg)
{
@@ -295,16 +302,10 @@ dir_iterator_t *dir_tree_iterator_create(const char *path,
((dir_iterator_t *)it)->next = next;
((dir_iterator_t *)it)->read_link = read_link;
((dir_iterator_t *)it)->open_subdir = open_subdir;
+ ((dir_iterator_t *)it)->ignore_subdir = ignore_subdir;
return (dir_iterator_t *)it;
fail:
free(it);
return NULL;
}
-
-void dir_tree_iterator_skip(dir_iterator_t *base)
-{
- dir_tree_iterator_t *it = (dir_tree_iterator_t *)base;
-
- pop(it);
-}
diff --git a/lib/io/src/unix/dir_iterator.c b/lib/io/src/unix/dir_iterator.c
index d67fe83..d2727ad 100644
--- a/lib/io/src/unix/dir_iterator.c
+++ b/lib/io/src/unix/dir_iterator.c
@@ -121,6 +121,11 @@ static int dir_next(dir_iterator_t *base, dir_entry_t **out)
return it->state;
}
+static void dir_ignore_subdir(dir_iterator_t *it)
+{
+ (void)it;
+}
+
static int dir_open_subdir(dir_iterator_t *base, dir_iterator_t **out)
{
const unix_dir_iterator_t *it = (const unix_dir_iterator_t *)base;
@@ -160,6 +165,7 @@ static int dir_open_subdir(dir_iterator_t *base, dir_iterator_t **out)
((dir_iterator_t *)sub)->next = dir_next;
((dir_iterator_t *)sub)->read_link = dir_read_link;
((dir_iterator_t *)sub)->open_subdir = dir_open_subdir;
+ ((dir_iterator_t *)sub)->ignore_subdir = dir_ignore_subdir;
*out = (dir_iterator_t *)sub;
return 0;
@@ -199,6 +205,7 @@ dir_iterator_t *dir_iterator_create(const char *path)
((dir_iterator_t *)it)->next = dir_next;
((dir_iterator_t *)it)->read_link = dir_read_link;
((dir_iterator_t *)it)->open_subdir = dir_open_subdir;
+ ((dir_iterator_t *)it)->ignore_subdir = dir_ignore_subdir;
return (dir_iterator_t *)it;
}
diff --git a/lib/io/src/win32/dir_iterator.c b/lib/io/src/win32/dir_iterator.c
index 23d00f4..94fd6e6 100644
--- a/lib/io/src/win32/dir_iterator.c
+++ b/lib/io/src/win32/dir_iterator.c
@@ -107,6 +107,11 @@ static void dir_iterator_destroy(sqfs_object_t *obj)
free(dir);
}
+static void dir_iterator_ignore_subdir(dir_iterator_t *it)
+{
+ (void)it;
+}
+
static int dir_iterator_open_subdir(dir_iterator_t *it, dir_iterator_t **out)
{
const dir_iterator_win32_t *dir = (const dir_iterator_win32_t *)it;
@@ -139,6 +144,7 @@ static int dir_iterator_open_subdir(dir_iterator_t *it, dir_iterator_t **out)
((dir_iterator_t *)sub)->next = dir_iterator_next;
((dir_iterator_t *)sub)->read_link = dir_iterator_read_link;
((dir_iterator_t *)sub)->open_subdir = dir_iterator_open_subdir;
+ ((dir_iterator_t *)sub)->ignore_subdir = dir_iterator_ignore_subdir;
sub->is_first = true;
sub->state = 0;
@@ -198,6 +204,7 @@ dir_iterator_t *dir_iterator_create(const char *path)
((dir_iterator_t *)it)->next = dir_iterator_next;
((dir_iterator_t *)it)->read_link = dir_iterator_read_link;
((dir_iterator_t *)it)->open_subdir = dir_iterator_open_subdir;
+ ((dir_iterator_t *)it)->ignore_subdir = dir_iterator_ignore_subdir;
it->is_first = true;
it->state = 0;
diff --git a/lib/io/test/dir_tree_iterator.c b/lib/io/test/dir_tree_iterator.c
index 46e0a56..0c735e2 100644
--- a/lib/io/test/dir_tree_iterator.c
+++ b/lib/io/test/dir_tree_iterator.c
@@ -152,7 +152,7 @@ int main(int argc, char **argv)
printf("READ %s\n", ent[i]->name);
if (!strcmp(ent[i]->name, "dirb/dirx"))
- dir_tree_iterator_skip(dir);
+ dir->ignore_subdir(dir);
}
ret = dir->next(dir, &ent[13]);
@@ -210,7 +210,7 @@ int main(int argc, char **argv)
printf("READ %s\n", ent[i]->name);
if (!strcmp(ent[i]->name, "dirb"))
- dir_tree_iterator_skip(dir);
+ dir->ignore_subdir(dir);
}
ret = dir->next(dir, &ent[9]);