aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-07-22 22:26:21 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-09-19 11:51:55 +0200
commitbfd932fb3470fa7250359da6ed5641182a10077c (patch)
treeaf54c3f9d5aa13e00bd922188106b04889ff2c91 /lib
parentaccd38b7034f6b9e292d4191afb39322fe943486 (diff)
sqfs2tar: replace hierarchy extraction with nested iterators
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Makemodule.am2
-rw-r--r--lib/common/src/hardlink.c101
2 files changed, 1 insertions, 102 deletions
diff --git a/lib/common/Makemodule.am b/lib/common/Makemodule.am
index 5549cc3..7c07d48 100644
--- a/lib/common/Makemodule.am
+++ b/lib/common/Makemodule.am
@@ -1,6 +1,6 @@
libcommon_a_SOURCES = include/common.h include/simple_writer.h \
include/compress_cli.h include/dir_tree.h \
- lib/common/src/hardlink.c lib/common/src/print_version.c \
+ lib/common/src/print_version.c \
lib/common/src/compress.c lib/common/src/comp_opt.c \
lib/common/src/parse_size.c lib/common/src/print_size.c \
lib/common/src/writer/init.c lib/common/src/writer/cleanup.c \
diff --git a/lib/common/src/hardlink.c b/lib/common/src/hardlink.c
deleted file mode 100644
index e43df33..0000000
--- a/lib/common/src/hardlink.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * hardlink.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "common.h"
-#include "util/rbtree.h"
-#include "util/util.h"
-
-#include <stdlib.h>
-#include <assert.h>
-#include <stdio.h>
-
-static int map_nodes(rbtree_t *inumtree, sqfs_hard_link_t **out,
- const sqfs_tree_node_t *n)
-{
- const sqfs_tree_node_t *target;
- sqfs_hard_link_t *lnk;
- rbtree_node_t *tn;
- sqfs_u32 idx;
- int ret;
-
- /* XXX: refuse to generate hard links to directories */
- if (n->children != NULL) {
- for (n = n->children; n != NULL; n = n->next) {
- ret = map_nodes(inumtree, out, n);
- if (ret != 0)
- return ret;
- }
- return 0;
- }
-
- if (!is_filename_sane((const char *)n->name, false))
- return SQFS_ERROR_CORRUPTED;
-
- idx = n->inode->base.inode_number;
- tn = rbtree_lookup(inumtree, &idx);
-
- 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)
- return SQFS_ERROR_ALLOC;
-
- lnk->inode_number = idx;
- ret = sqfs_tree_node_get_path(target, &lnk->target);
- if (ret != 0) {
- free(lnk);
- return ret;
- }
-
- if (canonicalize_name(lnk->target) != 0) {
- sqfs_free(lnk->target);
- free(lnk);
- return SQFS_ERROR_CORRUPTED;
- }
-
- lnk->next = (*out);
- (*out) = lnk;
- return 0;
-}
-
-static int compare_inum(const void *ctx, const void *lhs, const void *rhs)
-{
- sqfs_u32 l = *((const sqfs_u32 *)lhs), r = *((const sqfs_u32 *)rhs);
- (void)ctx;
-
- return l < r ? -1 : (l > r ? 1 : 0);
-}
-
-int sqfs_tree_find_hard_links(const sqfs_tree_node_t *root,
- sqfs_hard_link_t **out)
-{
- sqfs_hard_link_t *lnk = NULL;
- rbtree_t inumtree;
- int ret;
-
- ret = rbtree_init(&inumtree, sizeof(sqfs_u32),
- sizeof(sqfs_tree_node_t *),
- compare_inum);
- if (ret != 0)
- return ret;
-
- ret = map_nodes(&inumtree, out, root);
- rbtree_cleanup(&inumtree);
-
- if (ret != 0) {
- while ((*out) != NULL) {
- lnk = (*out);
- (*out) = lnk->next;
- free(lnk->target);
- free(lnk);
- }
- }
-
- return ret;
-}