Skip to content

Commit

Permalink
fix(tar): handle strip_prefix of root directory in mtree_mutate (#995)
Browse files Browse the repository at this point in the history
* tar: Add test case for root directory strip_prefix (#978)

* Use space delimiter to skip entry if missing path after strip_prefix
  • Loading branch information
j-eid authored Dec 11, 2024
1 parent cb6e9c3 commit f067a4f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/private/modify_mtree.awk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
# To avoid this, we append a slash to the directory path to make it a "full" entry.
components = split($1, _, "/");
if ($0 ~ /type=dir/ && components == 1) {
$1 = $1 "/";
if ($0 !~ /^ /) {
$1 = $1 "/";
}
else {
# this line is the root directory and only contains orphaned keywords, which will be discarded
next;
}
}
} else {
# this line declares some path under a parent directory, which will be discarded
Expand Down
38 changes: 38 additions & 0 deletions lib/tests/tar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,41 @@ assert_unused_listing(
"lib/tests/tar/unused/space in name.txt",
],
)

#############
# Example 16: Ensure that root directories are properly handled with strip_prefix (bug #978)
# Don't assume that files or directories exist after stripping the prefix. See (bug #851)

_SRCS16 = [
"src_file",
":fixture1",
]

mtree_spec(
name = "mtree16",
srcs = _SRCS16,
)

mtree_mutate(
name = "strip_prefix16",
mtree = ":mtree16",
strip_prefix = "lib",
)

tar(
name = "tar_strip_prefix16",
srcs = _SRCS16,
out = "16.tar",
mtree = "strip_prefix16",
)

assert_tar_listing(
name = "test_strip_prefix16",
actual = "tar_strip_prefix16",
expected = [
"drwxr-xr-x 0 0 0 0 Jan 1 2023 tests/",
"drwxr-xr-x 0 0 0 0 Jan 1 2023 tests/tar/",
"-rwxr-xr-x 0 0 0 21 Jan 1 2023 tests/tar/src_file",
"-rwxr-xr-x 0 0 0 7 Jan 1 2023 tests/tar/generated.txt",
],
)

0 comments on commit f067a4f

Please sign in to comment.