aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/common/serialize_fstree.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/lib/common/serialize_fstree.c b/lib/common/serialize_fstree.c
index 939b1c1..0f34d7d 100644
--- a/lib/common/serialize_fstree.c
+++ b/lib/common/serialize_fstree.c
@@ -145,19 +145,55 @@ out:
return ret;
}
+static int serialize_recursive(const char *filename, sqfs_writer_t *wr,
+ tree_node_t *root)
+{
+ bool has_subdirs = false;
+ tree_node_t *it;
+ int ret;
+
+ for (it = root->data.dir.children; it != NULL; it = it->next) {
+ if (S_ISDIR(it->mode)) {
+ has_subdirs = true;
+ break;
+ }
+ }
+
+ if (has_subdirs) {
+ for (it = root->data.dir.children; it != NULL; it = it->next) {
+ if (S_ISDIR(it->mode)) {
+ ret = serialize_recursive(filename, wr, it);
+ if (ret)
+ return ret;
+ }
+ }
+ }
+
+ for (it = root->data.dir.children; it != NULL; it = it->next) {
+ ret = serialize_tree_node(filename, wr, it);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
int sqfs_serialize_fstree(const char *filename, sqfs_writer_t *wr)
{
- size_t i;
int ret;
wr->super.inode_table_start = wr->outfile->get_size(wr->outfile);
- for (i = 0; i < wr->fs.inode_tbl_size; ++i) {
- ret = serialize_tree_node(filename, wr, wr->fs.inode_table[i]);
+ if (S_ISDIR(wr->fs.root->mode)) {
+ ret = serialize_recursive(filename, wr, wr->fs.root);
if (ret)
goto out;
}
+ ret = serialize_tree_node(filename, wr, wr->fs.root);
+ if (ret)
+ goto out;
+
ret = sqfs_meta_writer_flush(wr->im);
if (ret)
goto out;