Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tar): handle strip_prefix of root directory in mtree_mutate #995

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
],
)
Loading