Skip to content

Fix the copier:get operation to properly gather symlink information#6759

Merged
nalind merged 1 commit into
containers:mainfrom
BenjaminSchubert:bschubert/fix-symlink-copy
Apr 20, 2026
Merged

Fix the copier:get operation to properly gather symlink information#6759
nalind merged 1 commit into
containers:mainfrom
BenjaminSchubert:bschubert/fix-symlink-copy

Conversation

@BenjaminSchubert
Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

Previously, the copier was always dereferencing symlinks, even if noDerefSymlinks was set. This passed unnoticed as the test was not validating the symlink value.

This augments the test to validate the symlink target, and ensures the copier sets the information completely.

How to verify it

Remove the fix, run the copier tests, notice that there is no more symlinks in them

Which issue(s) this PR fixes:

None (I can create one if needed, this was discovered while working on #6737 )

Special notes for your reviewer:

Does this PR introduce a user-facing change?

I am unsure here, I don't think so?


@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 2, 2026
Copy link
Copy Markdown
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

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

A question about a change to a WalkDir callback, and I don't think that the additions to the tests are examining everything that we want them to.

Comment thread copier/copier.go Outdated
Comment thread copier/copier_test.go Outdated
isOriginallySymlink := false
expectedLinkTarget := ""
for _, origHdr := range testArchive.headers {
if origHdr.Name == hdr.Name && origHdr.Typeflag == tar.TypeSymlink {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like it would skip over items whose paths are changed for some reason, either because they were explicitly renamed due to a renames setting, or because they were copied from one subdirectory to another.

There are a number of the test cases where the expected set of items includes the contents of a directory that was specified as the source for the copy operation, where the contents of the directory, but not the directory itself, are expected to be copied to the destination.

It might be simpler to add a new field to the test cases which maps from the members of the items slice to the corresponding expected Linkname field values in the headers with matching Name values. This loop body could then populate a new map using the Name and Linkname values for every header it sees with type TypeSymlink, and then those maps could be compared when expectedContents and actualContents are compared.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good shout. I've split the commits in two now:

First commit will contain the expansion of the copier_test.go to validate the symlink content as of main branch
Second commit applies the fix and fixes the test for easier reviewing of what is changing

@BenjaminSchubert BenjaminSchubert force-pushed the bschubert/fix-symlink-copy branch 2 times, most recently from 981b85a to 0c18548 Compare April 9, 2026 10:22
Copy link
Copy Markdown
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

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

LGTM with a nit, and the two commits might as well be squashed since they touch some of the same test cases.

Comment thread copier/copier.go Outdated
if info.Mode()&os.ModeType == os.ModeSymlink {
target, err := os.Readlink(path)
if err != nil {
return "", fmt.Errorf("readlink(%q): %w", path, err)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: the standard library wraps the error with the path in a PathError result, and this would add the path again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, done. This is a pattern that's present multiple time in the same file, should I clean that up in a separate PR?

Previously, the copier was always dereferencing symlinks, even if
`noDerefSymlinks` was set. This passed unnoticed as the test was not
validating the symlink value.

This augments the test to validate the symlink target, and ensures the
copier sets the information completely.

Also expand the tests in the copier to validate the symlinks destinations too

Previously, this would only be validating the source, but never the
destination

Signed-off-by: Benjamin Schubert <bschubert15@bloomberg.net>
@BenjaminSchubert BenjaminSchubert force-pushed the bschubert/fix-symlink-copy branch from 0c18548 to 88d6873 Compare April 16, 2026 06:52
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 16, 2026
@BenjaminSchubert
Copy link
Copy Markdown
Contributor Author

@nalind This is now squashed and ready to go from my side. Thanks for the reviews!

Copy link
Copy Markdown
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

LGTM, I think CI failures are flakes. (I don't have permission to rerun them.)

@Honny1
Copy link
Copy Markdown
Member

Honny1 commented Apr 17, 2026

PTAL @containers/buildah-maintainers

Copy link
Copy Markdown
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@nalind nalind enabled auto-merge April 20, 2026 21:00
@nalind nalind merged commit 782f298 into containers:main Apr 20, 2026
40 checks passed
@BenjaminSchubert BenjaminSchubert deleted the bschubert/fix-symlink-copy branch April 21, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants