diff --git a/src/cloudstorage/drivers/local.py b/src/cloudstorage/drivers/local.py index e436aa8..d13f2c4 100644 --- a/src/cloudstorage/drivers/local.py +++ b/src/cloudstorage/drivers/local.py @@ -538,7 +538,6 @@ def get_blob(self, container: Container, blob_name: str) -> Blob: def get_blobs(self, container: Container) -> Iterable[Blob]: container_path = self._get_folder_path(container, validate=True) - for folder, sub_folders, files in os.walk(container_path, topdown=True): # Remove unwanted sub-folders for sub_folder in IGNORE_FOLDERS: @@ -549,7 +548,7 @@ def get_blobs(self, container: Container) -> Iterable[Blob]: full_path = os.path.join(folder, name) if not self._check_path_accessible(full_path): continue - object_name = pathlib.Path(full_path).name + object_name = pathlib.Path(full_path).relative_to(container.cdn_url).as_posix() yield self._make_blob(container, object_name) def download_blob(self, blob: Blob, destination: FileLike) -> None: diff --git a/tests/test_drivers_local.py b/tests/test_drivers_local.py index 7ee19f1..0d71d1f 100644 --- a/tests/test_drivers_local.py +++ b/tests/test_drivers_local.py @@ -1,3 +1,4 @@ +import io import os import shutil import multiprocessing as mp @@ -142,6 +143,15 @@ def test_container_get_blob(container, text_blob): assert text_get_blob == text_blob +def test_container_get_blobs(container): + container.upload_blob( + io.BytesIO(b'Hello'), + blob_name='some/where/hello.txt' + ) + + assert [blob.name for blob in container] == ['some/where/hello.txt'] + + def test_container_get_blob_invalid(container): blob_name = random_container_name()