summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClint Harrison <60013602+clint-stripe@users.noreply.github.com>2023-03-15 20:30:05 -0700
committerGitHub <noreply@github.com>2023-03-15 23:30:05 -0400
commitedd4d3d643f01e6ac5cb529fc9d7e01dc8c9367e (patch)
tree1bf9c9fb9c1028e1a1d8d2c3cb1a171369317b85
parentf117c6311be9fd6df675112f2b1dbe7ebc0978f5 (diff)
downloadbazelbuild-rules_pkg-edd4d3d643f01e6ac5cb529fc9d7e01dc8c9367e.tar.gz
pkg_tar should not prefix tree artifacts with ./ (#681)
-rw-r--r--pkg/private/tar/build_tar.py7
-rw-r--r--tests/tar/BUILD19
-rw-r--r--tests/tar/pkg_tar_test.py8
3 files changed, 32 insertions, 2 deletions
diff --git a/pkg/private/tar/build_tar.py b/pkg/private/tar/build_tar.py
index 08ee4d0..cea2167 100644
--- a/pkg/private/tar/build_tar.py
+++ b/pkg/private/tar/build_tar.py
@@ -232,6 +232,9 @@ class TarFile(object):
# Again, we expect /-style paths.
dest = normpath(dest)
+ # normpath may be ".", and dest paths should not start with "./"
+ dest = '' if dest == '.' else dest + '/'
+
if ids is None:
ids = (0, 0)
if names is None:
@@ -246,9 +249,9 @@ class TarFile(object):
dirs = sorted(dirs)
rel_path_from_top = root[len(tree_top):].lstrip('/')
if rel_path_from_top:
- dest_dir = dest + '/' + rel_path_from_top + '/'
+ dest_dir = dest + rel_path_from_top + '/'
else:
- dest_dir = dest + '/'
+ dest_dir = dest
for dir in dirs:
to_write[dest_dir + dir] = None
for file in sorted(files):
diff --git a/tests/tar/BUILD b/tests/tar/BUILD
index 07111d4..bd3712b 100644
--- a/tests/tar/BUILD
+++ b/tests/tar/BUILD
@@ -356,6 +356,7 @@ py_test(
":test-tar-tree-artifact",
":test-tar-tree-artifact-noroot",
":test-tar-with-runfiles",
+ ":test-tree-input-with-strip-prefix",
"//tests:testdata/tar_test.tar",
"//tests:testdata/tar_test.tar.bz2",
"//tests:testdata/tar_test.tar.gz",
@@ -471,3 +472,21 @@ pkg_tar(
":relative_links_tar",
],
)
+
+directory(
+ name = "generate_tree_with_prefix",
+ contents = "hello there",
+ filenames = [
+ "a/a",
+ "a/b",
+ ],
+ outdir = "tree_prefix_to_strip",
+)
+
+pkg_tar(
+ name = "test-tree-input-with-strip-prefix",
+ srcs = [
+ ":generate_tree_with_prefix",
+ ],
+ strip_prefix = "tree_prefix_to_strip",
+) \ No newline at end of file
diff --git a/tests/tar/pkg_tar_test.py b/tests/tar/pkg_tar_test.py
index 907441c..fabdffc 100644
--- a/tests/tar/pkg_tar_test.py
+++ b/tests/tar/pkg_tar_test.py
@@ -258,6 +258,14 @@ class PkgTarTest(unittest.TestCase):
]
self.assertTarFileContent('test_tar_leading_dotslash.tar', content)
+ def test_tar_with_tree_artifact_and_strip_prefix(self):
+ content = [
+ {'name': 'a', 'isdir': True},
+ {'name': 'a/a'},
+ {'name': 'a/b'},
+ ]
+ self.assertTarFileContent('test-tree-input-with-strip-prefix.tar', content)
+
if __name__ == '__main__':
unittest.main()