-
Notifications
You must be signed in to change notification settings - Fork 2.6k
avoid appending directory as file path in s3 driver Walk #4485
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
avoid appending directory as file path in s3 driver Walk #4485
Conversation
471166f
to
68e80d2
Compare
Signed-off-by: Flavian Missi <fmissi@redhat.com>
when a directory is empty, the s3 api lists it with a trailing slash. this causes the path to be appended twice to the walkInfo slice, causing purge uploads path transformations to panic when the `_uploads` is emtpy. this adds a check for file paths ending on slash, and do not append those as regular files to the walkInfo slice. fixes distribution#4358 Signed-off-by: Flavian Missi <fmissi@redhat.com>
68e80d2
to
2e7482c
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.
I need to have a proper look at this, but this seems like a bit of a "hack" 🤔
// to skip appending filePath to walkInfos if it ends in "/". the loop through | ||
// dirs will already have handled it in that case, so it's safe to continue this | ||
// loop. | ||
if strings.HasSuffix(filePath, "/") { |
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.
Hmm, curious. The fact that a "directory" is "leaking" into "files" makes me wonder about directoryDiff
func 🤔
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.
Ignore this wondering, see: #4485 (comment)
Yeah that's fair. I'll dig some more and see if there's a better way to solve this.
The claim that directory paths are omitted is only true when the directory in question is not empty. Here's a sample output of list objects v2:
|
I have often wondered about that comment, though I can't remember if I ever looked into whether those statements hold 🥲 Ah them pesky edge conditions.........I'd still prefer modifying |
After looking into it I think
It works as expected:
Could you expand on how you would expect The entire loop through Anyways, I'll pause this while I wait for further feedback. |
I was speculating. I didn't make any recommendations or say anything other than "it makes me wonder" which is does/did. I'd have to zoom in when I find some free time. |
Ohh, thanks for clarifying. |
oh my look at what I found: 87cbd09#diff-69ca1a0abf51616b5031c87b33ce5a35fb6439b5bcd744aef65ddbc2131ec431R170 EDIT: this is the commit that removed that test: f78d81e |
Removing a test explains why the older version doesn't panic? Very strange and kinda.... worrying |
oh you mean this #3302 |
Ok, makes sense. Thanks for digging in. Let's roll with this then! |
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.
PTAL @Jamstah
// to skip appending filePath to walkInfos if it ends in "/". the loop through | ||
// dirs will already have handled it in that case, so it's safe to continue this | ||
// loop. | ||
if strings.HasSuffix(filePath, "/") { |
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.
Ignore this wondering, see: #4485 (comment)
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, @Jamstah should probably take a look too though
}, | ||
}) | ||
if err != nil { | ||
t.Logf("DeleteObjectsWithContext resp: %+v", resp) |
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.
thanks for these extras, they'll be useful for test debugging to someone one day
when a directory is empty, the s3 api lists it with a trailing slash.
this causes the path to be appended twice to the walkInfo slice, causing
purge uploads path transformations to panic when the
_uploads
isemtpy.
this adds a check for file paths ending on slash, and do not append
those as regular files to the walkInfo slice.
fixes #4358