s3fs icon indicating copy to clipboard operation
s3fs copied to clipboard

Skip the current directory entity when running 'ls' or 'listdir'

Open rilshok opened this issue 5 months ago • 3 comments

When using S3FileSystem.ls or S3FileSystem.listdir, zero-sized objects that serve as directory markers in S3 were incorrectly listed as files.

Amazon S3 employs a flat object storage model, but its console interface allows users to create "folders" by adding zero-size objects with keys ending in a delimiter (e.g., myfolder/). These objects act as placeholders to visually represent directories but are not actual files.

This PR implements a check to skip zero-size objects that match the current directory prefix during listing operations.

rilshok avatar Aug 23 '25 14:08 rilshok

Thanks for submitting. I will comment more on Monday and after the tests have run. I will say, that there is extensive conversation around this topic already in this repo, and that such a change will need extensive testing. I also don't see any reference to terminating "/", but I only took a 2min look.

martindurant avatar Aug 24 '25 02:08 martindurant

I am surprised to see only one failure! Of course, the tests do NOT tend to make placeholder files, since we know they are problematic and unnecessary.

I would expect, that bulk rm may fail in the case of placeholders, since the files deleted will be those returned by find(), and not include them - so only normal files will be deleted and not the "directories", leaving the tree structure erroniously in place. This should be explicitly tested.

martindurant avatar Aug 26 '25 02:08 martindurant

Yes, you are right that this scenario needs to be considered.

rilshok avatar Aug 27 '25 12:08 rilshok