-
Notifications
You must be signed in to change notification settings - Fork 86
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
tarfs: follow hardlinks in ReadFile
#1305
tarfs: follow hardlinks in ReadFile
#1305
Conversation
I wanted to note that I don't know if this behavior is consistent. For example, perhaps there's a flag you can pass to |
8745bcb
to
24f2cf0
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1305 +/- ##
==========================================
- Coverage 55.79% 55.76% -0.04%
==========================================
Files 265 265
Lines 16552 16562 +10
==========================================
Hits 9236 9236
- Misses 6357 6365 +8
- Partials 959 961 +2 ☔ View full report in Codecov by Sentry. |
2b4d980
to
1786a01
Compare
The more I think about this PR, the more I wonder if this is the right approach. It makes me wonder if we should move the |
1786a01
to
6fdd963
Compare
pkg/tarfs/tarfs_test.go
Outdated
t.Helper() | ||
// This is a perfect candidate for using test.GenerateFixture, but | ||
// creates an import cycle. | ||
f, err := os.Create(filepath.Join(tmp, path.Base(t.Name()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: filepath.Base
unless there's a specific reason path
is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was copied from the run
function in TestSymlinks
🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I used path
throughout and swapped specific uses because io/fs
mandates forward-slash paths and go just handles forward-slash paths, so it's moot unless the path could be absolute.
pkg/tarfs/tarfs.go
Outdated
switch { | ||
case typ.IsRegular() && i.h.Typeflag != tar.TypeLink: | ||
r = tar.NewReader(io.NewSectionReader(f.r, i.off, i.sz)) | ||
case typ.IsRegular() && i.h.Typeflag == tar.TypeLink: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious would all this just be equivalent to return f.ReadFile(i.h.Linkname)
? If so, should we just combine this case and the symlink check into a single case?
I like the idea of implementing this as closely to Also, |
Ya know... When I was digging into this before, I saw the note at the bottom of https://pkg.go.dev/archive/tar#Reader.Read and assumed the So never mind. Now I want to use I guess it really comes down to the hint at the top of Lines 452 to 454 in 813e7cc
I'm open to having my mind changed, but maintaining these two functions that are very similar but diverge due to the allocation of a tarfs.file struct in such a critical code path isn't worth it. The PR proves it. Maybe I'm missing something though (like maybe tarfs.file.Read would cause us to allocate the data twice? not sure)
|
5fae3dd
to
608e0c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
On the rebase, can I trouble you to rewrite the commit summary line to not have fix(tarfs)
but rather just tarfs
? We try to follow something closer to the go commit style than "conventional commits".
I'll look though how this is handled in #669 |
Yup, will do! Before we merge this, do you mind giving your thoughts on #1305 (comment)? I wonder if we can/should remove |
Signed-off-by: Brad Lugo <[email protected]>
608e0c2
to
e8f9aff
Compare
https://github.com/quay/claircore/blob/main/docs/contributor/commit-style.md |
/fast-forward |
ReadFile
ReadFile
Description
In
ReadFile
, we either follow symlinks or attempt to read the amount of data from the tar as specified by theSize
field intar.Header
. When we come across a hardlink, however, we essentially tell the caller that the file is empty since theSize
is0
.These changes to
ReadFile
are largely based on the changes @hdonnay made toOpen
for handling hardlinks: 48317f8