aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/hardlink.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/lib/common/hardlink.c b/lib/common/hardlink.c
index f28620f..4657bc3 100644
--- a/lib/common/hardlink.c
+++ b/lib/common/hardlink.c
@@ -24,8 +24,9 @@ static int map_nodes(rbtree_t *inumtree, sqfs_hard_link_t **out,
/* XXX: refuse to generate hard links to directories */
if (n->children != NULL) {
for (n = n->children; n != NULL; n = n->next) {
- if (map_nodes(inumtree, out, n))
- return -1;
+ ret = map_nodes(inumtree, out, n);
+ if (ret != 0)
+ return ret;
}
return 0;
}
@@ -36,23 +37,21 @@ static int map_nodes(rbtree_t *inumtree, sqfs_hard_link_t **out,
idx = n->inode->base.inode_number;
tn = rbtree_lookup(inumtree, &idx);
- if (tn == NULL) {
- ret = rbtree_insert(inumtree, &idx, &n);
- if (ret != 0)
- goto fail_insert;
- return 0;
- }
+ if (tn == NULL)
+ return rbtree_insert(inumtree, &idx, &n);
target = *((const sqfs_tree_node_t **)rbtree_node_value(tn));
lnk = calloc(1, sizeof(*lnk));
if (lnk == NULL)
- goto fail_oom;
+ return SQFS_ERROR_ALLOC;
lnk->inode_number = idx;
ret = sqfs_tree_node_get_path(target, &lnk->target);
- if (ret != 0)
- goto fail_path;
+ if (ret != 0) {
+ free(lnk);
+ return ret;
+ }
if (canonicalize_name(lnk->target) == 0) {
lnk->next = (*out);
@@ -62,18 +61,6 @@ static int map_nodes(rbtree_t *inumtree, sqfs_hard_link_t **out,
free(lnk);
}
return 0;
-fail_path:
- sqfs_perror(NULL, "re-constructing hard link path", ret);
- free(lnk);
- return -1;
-fail_oom:
- fputs("detecting hard links in file system tree: out of memory\n",
- stderr);
- free(lnk);
- return -1;
-fail_insert:
- sqfs_perror(NULL, "detecting hard links in file system tree", ret);
- return -1;
}
static int compare_inum(const void *ctx, const void *lhs, const void *rhs)
@@ -94,11 +81,8 @@ int sqfs_tree_find_hard_links(const sqfs_tree_node_t *root,
ret = rbtree_init(&inumtree, sizeof(sqfs_u32),
sizeof(sqfs_tree_node_t *),
compare_inum);
- if (ret != 0) {
- sqfs_perror(NULL,
- "detecting hard links in file system tree", ret);
- return -1;
- }
+ if (ret != 0)
+ return ret;
ret = map_nodes(&inumtree, out, root);
rbtree_cleanup(&inumtree);
@@ -110,8 +94,7 @@ int sqfs_tree_find_hard_links(const sqfs_tree_node_t *root,
free(lnk->target);
free(lnk);
}
- return -1;
}
- return 0;
+ return ret;
}