summaryrefslogtreecommitdiff
path: root/bin/sqfs2tar/write_tree.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-05-27 15:40:05 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-05-30 17:49:40 +0200
commit4840d9b654f302ff5bb8aba2e04331374bf6c0ef (patch)
tree46caf8b80592d9ecdc26beeee1e1303389ca3d03 /bin/sqfs2tar/write_tree.c
parent36e70b384e1360e47f473be54ef3c0599bf82844 (diff)
sqfs2tar: Move hard link detection to tree-repacking code
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/sqfs2tar/write_tree.c')
-rw-r--r--bin/sqfs2tar/write_tree.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/bin/sqfs2tar/write_tree.c b/bin/sqfs2tar/write_tree.c
index a84c20e..28e1cf0 100644
--- a/bin/sqfs2tar/write_tree.c
+++ b/bin/sqfs2tar/write_tree.c
@@ -6,6 +6,7 @@
*/
#include "sqfs2tar.h"
+static sqfs_hard_link_t *links = NULL;
static unsigned int record_counter;
static sqfs_hard_link_t *find_hard_link(const char *name, sqfs_u32 inum)
@@ -23,7 +24,7 @@ static sqfs_hard_link_t *find_hard_link(const char *name, sqfs_u32 inum)
return lnk;
}
-int write_tree_dfs(const sqfs_tree_node_t *n)
+static int write_tree_dfs(const sqfs_tree_node_t *n)
{
sqfs_hard_link_t *lnk = NULL;
tar_xattr_t *xattr = NULL;
@@ -133,3 +134,31 @@ out_skip:
free(name);
return ret;
}
+
+int write_tree(const sqfs_tree_node_t *n)
+{
+ sqfs_hard_link_t *lnk;
+ int status = -1;
+
+ if (!no_links) {
+ if (sqfs_tree_find_hard_links(n, &links))
+ return -1;
+
+ for (lnk = links; lnk != NULL; lnk = lnk->next) {
+ lnk->target = assemble_tar_path(lnk->target, false);
+
+ if (lnk->target == NULL)
+ goto out_links;
+ }
+ }
+
+ status = write_tree_dfs(n);
+out_links:
+ while (links != NULL) {
+ lnk = links;
+ links = links->next;
+ free(lnk->target);
+ free(lnk);
+ }
+ return status;
+}