Skip to content

Fix pkg_tar directory entries #647

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion pkg/private/tar/build_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ def add_manifest_entry(self, entry_list, file_attributes):
elif entry.entry_type == manifest.ENTRY_IS_EMPTY_FILE:
self.add_empty_file(entry.dest, **attrs)
else:
self.add_file(entry.src, entry.dest, **attrs)
if os.path.isdir(entry.src):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the place we should fix it.
For correctness, it needs to be in pkg.bzl, where we test that the input file has is_directory set. But we are already doing that.

self.add_tree(entry.src, entry.dest, **attrs)
else:
self.add_file(entry.src, entry.dest, **attrs)


def main():
Expand Down
14 changes: 14 additions & 0 deletions tests/tar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ genrule(
cmd = "for i in $(OUTS); do echo 1 >$$i; done",
)

genrule(
name = "generate_dir_file",
outs = ["lib"],
cmd = "mkdir -p $@; echo 1 >$@/nsswitch.conf",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a case we should actively support. It doesn't work in remote build situations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the behavior is at least currently inconsistent with zip files so not sure what best option here is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this ctx.actions.declare_directory based rule look correct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks mostly right. It does a declare_directory, then passes the .path of that to some tool to fill in.

)

pkg_tar(
name = "test_tar_dir_file",
srcs = [
":generate_dir_file",
],
out = "dir_file.tar",
)

directory(
name = "generate_tree",
contents = "hello there",
Expand Down