Skip to content

Commit 1848729

Browse files
committed
Fix pkg_tar directory entries
Directories appear to work for zip files but not tar files. This should ensure we don't try to process directories as normal files. Fixes issues like: rules_pkg/pkg/private/tar/tar_writer.py", line 242, in add_file with open(file_content, 'rb') as f: IsADirectoryError: [Errno 21] Is a directory: 'bazel-out/darwin-fastbuild/bin/py/selenium/webdriver/common/devtools/v106'
1 parent 8e65d2f commit 1848729

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pkg/private/tar/build_tar.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ def add_manifest_entry(self, entry_list, file_attributes):
309309
elif entry.entry_type == manifest.ENTRY_IS_EMPTY_FILE:
310310
self.add_empty_file(entry.dest, **attrs)
311311
else:
312-
self.add_file(entry.src, entry.dest, **attrs)
312+
if os.path.isdir(entry.src):
313+
self.add_tree(entry.src, entry.dest, **attrs)
314+
else:
315+
self.add_file(entry.src, entry.dest, **attrs)
313316

314317

315318
def main():

tests/tar/BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ genrule(
6060
cmd = "for i in $(OUTS); do echo 1 >$$i; done",
6161
)
6262

63+
genrule(
64+
name = "generate_dir_file",
65+
outs = ["lib"],
66+
cmd = "mkdir -p $@; echo 1 >$@/nsswitch.conf",
67+
)
68+
69+
pkg_tar(
70+
name = "test_tar_dir_file",
71+
srcs = [
72+
":generate_dir_file",
73+
],
74+
out = "dir_file.tar",
75+
)
76+
6377
directory(
6478
name = "generate_tree",
6579
contents = "hello there",

0 commit comments

Comments
 (0)