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 spaces in input filenames #835

Merged
merged 1 commit into from
May 8, 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
6 changes: 5 additions & 1 deletion lib/private/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def _to_rlocation_path(file, workspace):
else:
return workspace + "/" + file.short_path

def _vis_encode(filename):
# TODO(#794): correctly encode all filenames by using vis(3) (or porting it)
return filename.replace(" ", "\\040")

def _expand(file, expander, transform = to_repository_relative_path):
expanded = expander.expand(file)
lines = []
Expand All @@ -193,7 +197,7 @@ def _expand(file, expander, transform = to_repository_relative_path):
parent = "/".join(segments[:i])
lines.append(_mtree_line(parent, "dir"))

lines.append(_mtree_line(path, "file", content = e.path))
lines.append(_mtree_line(_vis_encode(path), "file", content = _vis_encode(e.path)))
return lines

def _mtree_impl(ctx):
Expand Down
4 changes: 4 additions & 0 deletions lib/tests/tar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ tar(
"treeartifact",
],
out = "7.tar",
# When running remote, BB lays out files with inodes that mtree optimizes into a hardlink
tags = ["no-remote-exec"],
)

assert_tar_listing(
Expand All @@ -229,9 +231,11 @@ assert_tar_listing(
"drwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/srcdir/",
"-rwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/srcdir/info",
"-rwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/srcdir/pkg",
"-rwxr-xr-x 0 0 0 1 Jan 1 2023 lib/tests/tar/srcdir/space in name.txt",
"drwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/treeartifact/",
"-rwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/treeartifact/info",
"-rwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/treeartifact/pkg",
"-rwxr-xr-x 0 0 0 1 Jan 1 2023 lib/tests/tar/treeartifact/space in name.txt",
],
)

Expand Down
1 change: 1 addition & 0 deletions lib/tests/tar/srcdir/space in name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e