Skip to content

opendir() fails on same path that listdir() works on #80

Description

@dargueta

Not sure why, but opendir() apparently only works on the root directory. If you try to use it with a subdirectory that exists, you get a ResourceNotFound error.

>>> s3 = fs.open_fs("s3://my-bucket")
# The directory clearly exists...
>>> s3.listdir("/path/to/directory")
['foo.txt', 'bar.txt']
# ... but sad times if you try to open it
>>> root = s3.opendir("/path/to/directory")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/dargueta/.pyenv/versions/3.7.6/envs/gds/lib/python3.7/site-packages/fs/base.py", line 1207, in opendir
if not self.getbasic(path).is_dir:
File "/Users/dargueta/.pyenv/versions/3.7.6/envs/gds/lib/python3.7/site-packages/fs/base.py", line 1525, in getbasic
return self.getinfo(path, namespaces=["basic"])
File "/Users/dargueta/.pyenv/versions/3.7.6/envs/gds/lib/python3.7/site-packages/fs_s3fs/_s3fs.py", line 441, in getinfo
raise errors.ResourceNotFound(path)
fs.errors.ResourceNotFound: resource '/path/to/directory' not found

I've tried this both with the leading and trailing slash and it still breaks.

If I try this...

>>> s3 = fs.open_fs("s3://my-bucket/path/to/directory")
>>> s3.listdir("/")
['foo.txt', 'bar.txt']
# I can open files
>>> with s3.open('foo.txt', 'rb') as fd:
... print(len(fd.read()))
36256176

So far so good. However, if I try using filterdir() it breaks even though I was just able to open a .txt file:

>>> list(s3.filterdir("*.txt"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/dargueta/.pyenv/versions/3.7.6/envs/gds/lib/python3.7/site-packages/fs_s3fs/_s3fs.py", line 695, in scandir
info = self.getinfo(path)
File "/Users/dargueta/.pyenv/versions/3.7.6/envs/gds/lib/python3.7/site-packages/fs_s3fs/_s3fs.py", line 451, in getinfo
obj = self._get_object(path, _key)
File "/Users/dargueta/.pyenv/versions/3.7.6/envs/gds/lib/python3.7/site-packages/fs_s3fs/_s3fs.py", line 351, in _get_object
return obj
File "/Users/dargueta/.pyenv/versions/3.7.6/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/Users/dargueta/.pyenv/versions/3.7.6/envs/gds/lib/python3.7/site-packages/fs_s3fs/_s3fs.py", line 183, in s3errors
raise errors.ResourceNotFound(path)
fs.errors.ResourceNotFound: resource '*.txt' not found

I suspect something's wrong with the way SubFS is getting created.

(Duplicate of #8 but that was closed a long time ago with no resolution)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions