Skip to content

Preserve leading slashes in S3 directory listings - #1097

Open
samhoon000 wants to merge 1 commit into
fsspec:mainfrom
samhoon000:fix/preserve-leading-slash-in-listings
Open

samhoon000 wants to merge 1 commit into
fsspec:mainfrom
samhoon000:fix/preserve-leading-slash-in-listings

Conversation

@samhoon000

@samhoon000 samhoon000 commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

S3FileSystem.ls() drops leading slashes from the object-key portion of the list prefix. Listing s3://bucket//test_path/ can return entries under s3://bucket/test_path/ or raise FileNotFoundError.

Build the prefix from the key returned by split_path(), preserving the slashes that belong to the key. The regression tests store objects under both prefixes and check that listing each prefix returns its own directory. They cover keys beginning with one or two slashes.

Validation

  • Ran the four cases selected by pytest -q s3fs/tests/test_s3fs.py -k 'leading_slashes_in_key or leading_forward_slash or test_lsdir' on Windows with Moto. All four passed after the fix. Both new cases failed before the fix because the leading-slash path returned the regular path's directory.
  • The expanded listing selection, pytest -q s3fs/tests/test_s3fs.py -k 'listing or test_ls or leading_forward_slash', passed all 10 cases.
  • pytest -q s3fs: 358 passed, 2 skipped, 4 xfailed, 50 failed, and 89 setup errors on Windows. The same 47 derived-suite failures and 89 setup errors occurred on the unchanged base commit. The three remaining core failures also reproduced on the base commit, including two Windows path cases and an async test without its pytest plugin.
  • pre-commit run --files s3fs/core.py s3fs/tests/test_s3fs.py and git diff --check passed.

Fixes #770.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty directory in aws key breaks listdir api.

1 participant