fix(tar): handle spaces in input filenames (#835)

This commit is contained in:
Alex Eagle 2024-05-07 17:52:35 -07:00 committed by GitHub
parent d8d22cbf77
commit b15dc31a81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 1 deletions

View File

@ -183,6 +183,10 @@ def _to_rlocation_path(file, workspace):
else: else:
return workspace + "/" + file.short_path 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): def _expand(file, expander, transform = to_repository_relative_path):
expanded = expander.expand(file) expanded = expander.expand(file)
lines = [] lines = []
@ -193,7 +197,7 @@ def _expand(file, expander, transform = to_repository_relative_path):
parent = "/".join(segments[:i]) parent = "/".join(segments[:i])
lines.append(_mtree_line(parent, "dir")) 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 return lines
def _mtree_impl(ctx): def _mtree_impl(ctx):

View File

@ -217,6 +217,8 @@ tar(
"treeartifact", "treeartifact",
], ],
out = "7.tar", 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( assert_tar_listing(
@ -229,9 +231,11 @@ assert_tar_listing(
"drwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/srcdir/", "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/info",
"-rwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/srcdir/pkg", "-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/", "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/info",
"-rwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/treeartifact/pkg", "-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",
], ],
) )

View File

@ -0,0 +1 @@
e