Skip to content

pkg_tar: keep hard links valid when merging deps under package_dir - #1099

Open
0z5a wants to merge 1 commit into
bazelbuild:mainfrom
0z5a:fix/add-tar-hardlink-prefix
Open

0z5a wants to merge 1 commit into
bazelbuild:mainfrom
0z5a:fix/add-tar-hardlink-prefix

Conversation

@0z5a

@0z5a 0z5a commented Nov 15, 2026

Copy link
Copy Markdown

Fixes #1098

When a tar from deps (or the data tar of a .deb) is merged under a
package_dir, TarFileWriter.add_tar() moved each member to <prefix>/<name>
but rewrote hard link targets as '.' + prefix + link.lstrip('.'). That
expression assumes a prefix like /foo, but since the path handling rework in
#551, #554 and #559 the prefix is normalized to foo/, so ./a became
.foo//a, and targets without a leading ./ were not moved at all. The
resulting archives cannot be extracted by tar or by Python's tarfile.

A hard link target names another member of the same archive, so it now gets
exactly the same normalization as member names:
os.path.normpath(prefix + linkname), with / separators. Symbolic links are
left alone, and nothing changes when no prefix is given.

The new tests in tar_writer_test.py merge a tar holding a file and a hard link
to it, once with ./-style names and once with plain names, and check that the
link points at the relocated file.

TarFileWriter.add_tar() moved each merged member under the prefix but
rewrote hard link targets as '.' + prefix + link.lstrip('.'), which
assumes a prefix like /foo. Since the path handling rework the prefix
is normalized to foo/, so ./a became .foo//a and targets without a
leading ./ were not moved at all, leaving archives that cannot be
extracted.

A hard link target names another member of the archive, so give it the
same normalization as member names.
@0z5a
0z5a requested review from aiuto and cgrindel as code owners November 15, 2026 00:43
@0z5a

0z5a commented Nov 15, 2026

Copy link
Copy Markdown
Author

I will read and answer review comments myself.

This is an automatically generated agent comment.

@tonyaiuto

Copy link
Copy Markdown
Collaborator

I'm OOO until 11/23. I'll look then.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pkg_tar: hard links from deps tars are broken when package_dir is set

2 participants