scottwernervt / cloudstorage

Unified cloud storage API for storage services.
http://cloudstorage.readthedocs.io/en/latest/
MIT License
93 stars 27 forks source link

Blob not found when iterating over container containing blobs in subfolders #80

Open snorrea opened 3 years ago

snorrea commented 3 years ago

The following fails:

from cloudstorage.drivers.local import LocalDriver

storage = LocalDriver(key="./foobar/")
storage.create_container("foo")
container = storage.get_container("foo")
container.upload_blob("./todo.md", blob_name=f"12/1231/todo.md")
for b in container:
    print(b.path, b.name)

With the following trace:

FileNotFoundError                         Traceback (most recent call last)
~/.pyenv/versions/3.8.2/lib/python3.8/site-packages/cloudstorage/drivers/local.py in _make_blob(self, container, object_name)
    358         try:
--> 359             stat = os.stat(str(object_path))
    360         except FileNotFoundError:

FileNotFoundError: [Errno 2] No such file or directory: 'foobar/foo/todo.md'

During handling of the above exception, another exception occurred:

NotFoundError                             Traceback (most recent call last)
<ipython-input-11-cae0a547d03a> in <module>
      5 container = storage.get_container("foo")
      6 container.upload_blob("./todo.md", blob_name=f"12/1231/todo.md")
----> 7 for b in container:
      8     print(b.path, b.name)

~/.pyenv/versions/3.8.2/lib/python3.8/site-packages/cloudstorage/drivers/local.py in get_blobs(self, container)
    551                     continue
    552                 object_name = pathlib.Path(full_path).name
--> 553                 yield self._make_blob(container, object_name)
    554 
    555     def download_blob(self, blob: Blob, destination: FileLike) -> None:

~/.pyenv/versions/3.8.2/lib/python3.8/site-packages/cloudstorage/drivers/local.py in _make_blob(self, container, object_name)
    359             stat = os.stat(str(object_path))
    360         except FileNotFoundError:
--> 361             raise NotFoundError(messages.BLOB_NOT_FOUND % (object_name, container.name))
    362 
    363         meta_data = {}

NotFoundError: Blob 'todo.md' not found in container 'foo'.

Is this expected behaviour? The file is created in subfolders as expected...