summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-08-26 10:43:31 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-08-26 10:55:21 +0200
commitce8d6217fe7ed4d40af23242be4eaef8e53385a3 (patch)
tree4c67811a2524cbf0e9f4dd3cf0d0c586ab00d019
parentb7052efb163e90c40be9f2886ab1e207048bc70d (diff)
Fix tree node path generation for detached sub trees
The function sqfs_tree_node_get_path is used in several places within rdsquashfs to produce a path for a tree node, either when describing the file system, or when unpacking it. Unpacking can be done on sub-trees as well as the entire tree, in which case the root of the sub-tree has its parent pointer removed, so the full path terminates at the new root. This works with directories, since they receive special case handling anyway, but fails if the sub-tree to unpack is only a single file because the sqfs_tree_node_get_path function assumes that we are at the tree root and returns "/" as a path, which gets normalized to "". This commit adds a workaround to the function to simply use the nodes name (if available) in that case instead. The describe case in rdsquashfs is unaffacted, since it always starts at the root. Likewise, the sqfs2tar case should also be unaffacted, since it already employs special case handling for the [sub] tree root node. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/common/get_path.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/common/get_path.c b/lib/common/get_path.c
index bdc6c3f..72ed1bd 100644
--- a/lib/common/get_path.c
+++ b/lib/common/get_path.c
@@ -15,8 +15,12 @@ char *sqfs_tree_node_get_path(const sqfs_tree_node_t *node)
char *str, *ptr;
size_t len = 0;
- if (node->parent == NULL)
+ if (node->parent == NULL) {
+ if (node->name[0] != '\0')
+ return strdup((const char *)node->name);
+
return strdup("/");
+ }
for (it = node; it != NULL && it->parent != NULL; it = it->parent) {
len += strlen((const char *)it->name) + 1;