Skip to content
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
11 changes: 6 additions & 5 deletions distroless/private/flatten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ if [[ "$deduplicate" == "True" ]]; then
# number of occurrences of each path, and the second pass determines whether each entry is the final (or only)
# occurrence of that path.

$bsdtar --confirmation "$@" 2< <("${awk}" '
$bsdtar --confirmation -P -s ',^\([^/.]\),./\1,' "$@" 2< <("${awk}" '
function normalize(p) {
# Strip leading "./" and trailing "/" so that "./etc/" and "etc/" are treated as the same path.
sub(/^\.\//, "", p)
sub(/\/$/, "", p)
return p
if (p == "") return "/"
if (p ~ /^(\/|\.\/)/) {
return p
}
return "./" p
}
{
key = normalize($1)
Expand Down
58 changes: 45 additions & 13 deletions examples/flatten/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ assert_tar_listing(
name = "test_flatten_dedup_listing",
actual = "flatten_dedup",
expected = """\
examples/
examples/flatten/
examples/flatten/dir/
examples/flatten/dir/changelog
examples/flatten/dir/sub/
examples/flatten/dir/sub/content.txt
./examples/
./examples/flatten/
./examples/flatten/dir/
./examples/flatten/dir/changelog
./examples/flatten/dir/sub/
./examples/flatten/dir/sub/content.txt
""",
)

Expand All @@ -128,34 +128,66 @@ tar(
name = "dotslash_tar",
compress = "gzip",
mtree = [
"./etc/ type=dir uid=0 gid=0 mode=0755 time=0.0",
"./etc/sub/ type=dir uid=0 gid=0 mode=0755 time=0.0",
"./top/ type=dir uid=0 gid=0 mode=0755 time=0.0",
"./top/sub/ type=dir uid=0 gid=0 mode=0755 time=0.0",
],
)

tar(
name = "nodotslash_tar",
compress = "gzip",
mtree = [
"etc/ type=dir uid=0 gid=0 mode=0755 time=0.0",
"etc/sub/ type=dir uid=0 gid=0 mode=0755 time=0.0",
"top/ type=dir uid=0 gid=0 mode=0755 time=0.0",
"top/sub/ type=dir uid=0 gid=0 mode=0755 time=0.0",
],
)

genrule(
name = "absolute_tar_gen",
outs = ["absolute_tar.tar.gz"],
cmd = """
mkdir -p top
$(BSDTAR_BIN) -czf $@ -P -s ',^top,/top,' top/
""",
toolchains = ["@bsd_tar_toolchains//:resolved_toolchain"],
)

flatten(
name = "flatten_dedup_normalize",
deduplicate = True,
tars = [
":dotslash_tar",
":nodotslash_tar",
":dotslash_tar",
":absolute_tar_gen",
],
)

assert_tar_listing(
name = "test_flatten_dedup_normalize",
actual = "flatten_dedup_normalize",
expected = """\
etc/
etc/sub/
./top/
./top/sub/
/top/
""",
)

flatten(
name = "flatten_dedup_normalize_reversed",
deduplicate = True,
tars = [
":absolute_tar_gen",
":dotslash_tar",
":nodotslash_tar",
],
)

assert_tar_listing(
name = "test_flatten_dedup_normalize_reversed",
actual = "flatten_dedup_normalize_reversed",
expected = """\
/top/
./top/
./top/sub/
""",
)
Loading