fix: s3: isdir()#380
Merged
Merged
Conversation
Fix a bug in S3 where it incorrectly identified simple prefix matches as directories.
There was a problem hiding this comment.
Pull request overview
This PR fixes pfio.v2.S3.isdir() incorrectly treating forward-prefix collisions (e.g., abc vs abcde) as “non-existent directory” when list_objects_v2(MaxKeys=1) returns a non-matching prefix first. The fix makes the S3 listing unambiguous by querying with a trailing slash and considers the directory present if S3 returns either Contents or CommonPrefixes.
Changes:
- Update
S3.isdir()to usePrefix=f"{key}/"and determine existence via presence ofContents/CommonPrefixes. - Add a regression test that exercises prefix-collision cases (
abc/vsabcde/, and nestedxyz/abc*).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pfio/v2/s3.py |
Adjusts isdir() S3 listing logic to avoid forward-prefix collisions and correctly detect directory presence. |
tests/v2_tests/test_s3.py |
Adds coverage for the prefix-collision regression scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kuenishi
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix a bug in S3 where it incorrectly identified simple prefix matches as directories.
When a partially matching key already exists as shown below, and MaxKeys=1 is set to 1,
bus/would be retrieved first, but since it's notbush, the operation would fail, resulting in the directory being incorrectly identified as non-existent.bus/engine.txtbush/kusamura.txtThe solution is to prepend a
/suffix when performing the List operation and determine existence based on whether a Common Prefix or Contents exist. If at least one exists, we can safely consider this prefix as a directory presence, and the presence of the/suffix prevents simple prefix matching from failing.Related Issue(PR)s
closes #379
Effect
This is a just bug fix.