Skip to content

pci-4898 goarchive tarfs regression tests - #829

Closed
aliculPix4D wants to merge 1 commit into
masterfrom
pci-4898-goarchive-tarfs-regression-tests
Closed

aliculPix4D wants to merge 1 commit into
masterfrom
pci-4898-goarchive-tarfs-regression-tests

Conversation

@aliculPix4D

@aliculPix4D aliculPix4D commented Jul 22, 2026 •

Copy link
Copy Markdown

pci-4898 goarchive tarfs regression tests

After many, many discussions and attempts, I think I finally nailed it with this one :)

Originally, I tried:

While both commits would actually work, in both cases, something didn't feel right.

Hence, I went back to the original issues and PRs, to first realize that already:
concourse#9601

already (partially) added "regression tests" for: concourse#9597

I say partially because it added:

		{
			Name: "./symlink-dir/relative-symlink",
			Link: "../some-file",
			Mode: 0755,
		},
		{
			Name: "./symlink-dir/absolute-symlink",
			Link: "/some-file",
			Mode: 0755,
		},

to the archiveFiles fixture, but did not add any Expect check on them. Even though the fact that tarfs.Extract succeeded with them is good enough evidence (at least on linux, where these tests were running). Now, since in the CI (both Pix4D and upstream) we run these tests also on Windows, combined with the checks we do on all symlinks in this archiveFiles fixture: 595b603 is sufficient to catch any potential issue with this code on any platform.

Additionally, I abandoned the idea of resolving the symlinks by using os.ReadFile because it didn't feel right (it can't work for absolute symlinks, and it is perfectly valid to have dangling symlinks). We can actually keep it much simpler and just add the same check I did to report: golang/go#80073 (the actual bug). The only things that are important are that written symlink target metadata is valid on a given platform

Finally, I just extended all of this with a directory-type symlink since we saw issues with it on Windows 2019
6f04966

How can we verify that these tests actually catch what they are supposed to?

Just changing:

- err = root.Symlink(filepath.FromSlash(header.Linkname), filePath)
+ err = root.Symlink(header.Linkname, filePath)

in production code make this tests fail on Windows, and passing on Linux.

@aliculPix4D
aliculPix4D requested a review from a team as a code owner July 22, 2026 11:07
Comment thread go-archive/tarfs/extract_test.go Resolved
Comment thread go-archive/tarfs/extract.go Resolved

Expect(emptyDirInfo.IsDir()).To(BeTrue())

target, err := os.Readlink(filepath.Join(extractionDest, "some-symlink"))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

before only: some-symlink was checked, and no checks were done on relative-symlink and absolute-symlink

Comment thread go-archive/tarfs/extract_test.go Resolved
Comment thread go-archive/tarfs/extract_test.go Resolved
@aliculPix4D
aliculPix4D force-pushed the pci-4898-goarchive-tarfs-regression-tests branch 2 times, most recently from 8129c69 to 887dee1 Compare July 22, 2026 13:13
@aliculPix4D

Copy link
Copy Markdown
Author

Crap... I did a rebase mistake when droping the commit, so now we have 1 commit instead of 2... but the content is ok.

@odormond

Copy link
Copy Markdown

Crap... I did a rebase mistake when droping the commit, so now we have 1 commit instead of 2... but the content is ok.

Check your git reflog. That should let you find out what was the commit before your rebase. Then you can go back to it with git reset --hard HEAD@{n}.

For example, here is my reflog for tomato:

a9d24a156 (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: checkout: moving from fix-artifactory-assign-groups to master
6f5b2bb28 HEAD@{1}: rebase (finish): returning to refs/heads/fix-artifactory-assign-groups
6f5b2bb28 HEAD@{2}: rebase (pick): Update changelog
87277d2b0 HEAD@{3}: rebase (pick): ci: housekeeping: use uv to run artifactory_update_users
6b7a5b780 HEAD@{4}: rebase (pick): ci/artifactory: create proper python project
f68387e76 HEAD@{5}: rebase (start): checkout master
e0e84ad9a HEAD@{6}: commit (amend): Update changelog
10a78943a HEAD@{7}: commit: Update changelog
c54fa5d99 HEAD@{8}: rebase (finish): returning to refs/heads/fix-artifactory-assign-groups
c54fa5d99 HEAD@{9}: rebase (pick): ci: housekeeping: use uv to run artifactory_update_users
eef305005 HEAD@{10}: rebase (fixup): ci/artifactory: create proper python project
273cc6320 HEAD@{11}: rebase (start): checkout master
ef95fb88d HEAD@{12}: commit: fixup! ci/artifactory: create proper python project
b892cab77 HEAD@{13}: commit: ci: housekeeping: use uv to run artifactory_update_users
273cc6320 HEAD@{14}: commit: ci/artifactory: create proper python project

The top entry is the current state and the result of pulling master after I merged my PR for the fix-artifactory-assign-groups branch.
The HEAD@{1} to HEAD@{5} are the sequence of commit during the rebase onto master I did before merging the mentioned branch.
So, to go back to the state prior to the rebase, I could do git reset --hard HEAD@{6}.

Comment thread go-archive/tarfs/extract_test.go Outdated
Comment on lines 137 to 142
symlinkInfo, err := os.Lstat(filepath.Join(extractionDest, "some-symlink"))
Expect(err).NotTo(HaveOccurred())

if runtime.GOOS != "windows" {
Expect(symlinkInfo.Mode() & 0755).To(Equal(os.FileMode(0755)))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think this is needed anymore because the os.Readlink in verifySymlink should fail on regular file or directory.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note that AFAIK there is no way to change the mode bits of symlink. So if it is a symlink as os.Readlink succeeded, then its mode is 0755.

chmod() changes the mode of the file specified whose pathname is given in pathname, which is dereferenced if it is a symbolic link.
-- man 2 open

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Let me confirm I understood you correctly. You are saying that I can fully remove:

symlinkInfo, err := os.Lstat(filepath.Join(extractionDest, "some-symlink"))
Expect(err).NotTo(HaveOccurred())

if runtime.GOOS != "windows" {
	Expect(symlinkInfo.Mode() & 0755).To(Equal(os.FileMode(0755)))
}

because, if symlink was successfully created (already confirmed with os.Readlink) the mode must also match, so there is no need to even call os.Lstat?

I am lost though on this:

because the os.Readlink in verifySymlink should fail on regular file or directory.

Why are you mentioning the regular file or directory? os.Readlink is never called for them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if symlink was successfully created (already confirmed with os.Readlink) the mode must also match, so there is no need to even call os.Lstat?

Exactly.

Why are you mentioning the regular file or directory? os.Readlink is never called for them.

Well, if anyone mess with the test data, then the code might call os.Readlink on a file or directory so the test must fail (which would be the case).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed.

@aliculPix4D

aliculPix4D commented Jul 22, 2026 •

Copy link
Copy Markdown
Author

Check your git reflog.

I will for practice, but I don't actually see any added value in splitting in 2nd commit... so I will keep the PR as it is.

@odormond

Copy link
Copy Markdown

Check your git reflog.

I will for practice, but I don't actually see any added value in splitting in 2nd commit... so I will keep the PR as it is.

Sure. The PR is too small to bother with that. Just giving you a hint for more "interesting" times. :-)

- verify extracted symlinks preserve their expected targets across platforms.
- regression test for: concourse#9609 and golang/go#80073
@aliculPix4D
aliculPix4D force-pushed the pci-4898-goarchive-tarfs-regression-tests branch 2 times, most recently from 887dee1 to a02731e Compare July 23, 2026 09:08
Mode: 0755,
},
{
Name: "./symlink-dir/relative-symlink",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These relative and absolute symlinks were added in: concourse#9597

But the extractionTest was not extended to do any verification on them.

Sure, just the fact that:

		err := tarfs.Extract(extractionSrc, extractionDest)
		Expect(err).NotTo(HaveOccurred())

passes is almost a good enough test, but still.. Let's be consistent. This verification will allow us to verify that symlink targets use the correct path separators on each platform.

@aliculPix4D

Copy link
Copy Markdown
Author

Closing this one, as the same PR was merged upstream.

@aliculPix4D
aliculPix4D deleted the pci-4898-goarchive-tarfs-regression-tests branch July 28, 2026 06:58
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.

3 participants