Skip to content
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

S3Path.iterdir() gives wrong paths when used with trailing slash #146

Closed
theogaraj opened this issue Sep 22, 2023 · 1 comment · Fixed by #149
Closed

S3Path.iterdir() gives wrong paths when used with trailing slash #146

theogaraj opened this issue Sep 22, 2023 · 1 comment · Fixed by #149
Labels
bug 🐛 Something isn't working

Comments

@theogaraj
Copy link

Which operating system and Python version are you using?
Windows 11, Python 3.9.6

Which version of this project are you using?
0.1.3

What did you do?

  • Created an S3 bucket with a "folder" containing 3 text files.
  • Created an S3 path object using path of the folder, with trailing slash.
  • Listed folder contents using iterdir() method.

What did you expect to see?
Correct paths of each of the files

What did you see instead?
Extra slash in the paths.
I get the expected result:

  • if I don't have a trailing slash
  • if I get the filesystem object and use its ls() method.
>>> # scenario 1
>>> spath = UPath('s3://tj.test.bucket/firstsubfolder/')  # note trailing slash
>>> for f in spath.iterdir():
...     print(f)
...
s3://tj.test.bucket/firstsubfolder//
s3://tj.test.bucket/firstsubfolder//file_1.txt
s3://tj.test.bucket/firstsubfolder//file_2.txt
s3://tj.test.bucket/firstsubfolder//file_3.txt
>>>
>>> # scenario 2 - same spath but using filesystem.ls
>>> for f in spath.fs.ls(str(spath)):
...     print(f)
...
tj.test.bucket/firstsubfolder/
tj.test.bucket/firstsubfolder/file_1.txt
tj.test.bucket/firstsubfolder/file_2.txt
tj.test.bucket/firstsubfolder/file_3.txt
>>>
>>> # scenario 3 - no trailing slash
>>> spath = UPath('s3://tj.test.bucket/firstsubfolder')  # note NO trailing slash
>>> for f in spath.iterdir():
...     print(f)
...
s3://tj.test.bucket/firstsubfolder/
s3://tj.test.bucket/firstsubfolder/file_1.txt
s3://tj.test.bucket/firstsubfolder/file_2.txt
s3://tj.test.bucket/firstsubfolder/file_3.txt
@ap--
Copy link
Collaborator

ap-- commented Sep 23, 2023

Hi @theogaraj,

Thank you for reporting the issue!
I can reproduce it locally. Will need to think a bit about how to fix this together with #144.

Cheers,
Andreas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants