Repository navigation
pci-4898 goarchive tarfs regression tests - #829
aliculPix4D wants to merge 1 commit into
Conversation
|
|
||
| Expect(emptyDirInfo.IsDir()).To(BeTrue()) | ||
|
|
||
| target, err := os.Readlink(filepath.Join(extractionDest, "some-symlink")) |
There was a problem hiding this comment.
before only: some-symlink was checked, and no checks were done on relative-symlink and absolute-symlink
8129c69 to
887dee1
Compare
|
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 For example, here is my reflog for tomato: The top entry is the current state and the result of pulling master after I merged my PR for the |
| 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))) | ||
| } |
There was a problem hiding this comment.
I don't think this is needed anymore because the os.Readlink in verifySymlink should fail on regular file or directory.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.Readlinkis 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).
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
887dee1 to
a02731e
Compare
| Mode: 0755, | ||
| }, | ||
| { | ||
| Name: "./symlink-dir/relative-symlink", |
There was a problem hiding this comment.
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.
|
Closing this one, as the same PR was merged upstream. |
pci-4898 goarchive tarfs regression tests
After many, many discussions and attempts, I think I finally nailed it with this one :)
Originally, I tried:
os.ReadFile: 087624dWhile 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
archiveFilesfixture, but did not add anyExpectcheck on them. Even though the fact thattarfs.Extractsucceeded 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.ReadFilebecause 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 platformFinally, 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:
in production code make this tests fail on Windows, and passing on Linux.