From e648e6f169e3d06430dbf5f2967521763e0af125 Mon Sep 17 00:00:00 2001 From: DHUK Date: Thu, 29 Aug 2024 15:52:27 +0100 Subject: [PATCH] Don't trim paths in `list_file` if class initialized with no path Previously, if `S3SubdirectoryFileStore` was initialized with no path other than the s3 bucket ie. `s3://bucket-name` The returned paths would have the first letter trimmed incorrectly If self.path is not set we do not need to trim the returned paths This change, ensures that the returned paths are not incorrectly trimmed --- tests/storage/test_storage.py | 1 - xocto/storage/storage.py | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/storage/test_storage.py b/tests/storage/test_storage.py index 9122f9c5..b99b8ec0 100644 --- a/tests/storage/test_storage.py +++ b/tests/storage/test_storage.py @@ -175,7 +175,6 @@ def test_list_files(self, get_boto_bucket): Prefix="folder/a/b" ) - @pytest.mark.xfail(reason="Expose bug when listing files with no bucket path") @mock.patch.object(storage.S3FileStore, "_get_boto_bucket") def test_list_files_no_path(self, get_boto_bucket): get_boto_bucket.return_value = mock.Mock( diff --git a/xocto/storage/storage.py b/xocto/storage/storage.py index 3c30e348..aebebc2e 100644 --- a/xocto/storage/storage.py +++ b/xocto/storage/storage.py @@ -1013,10 +1013,12 @@ def list_s3_keys_page( return objects, next_token def list_files(self, namespace: str = "") -> Iterable[str]: + path_trim = 0 if self.path: + path_trim = len(self.path) + 1 namespace = os.path.join(self.path, namespace) full_paths = super().list_files(namespace) - yield from (path[len(self.path) + 1 :] for path in full_paths) + yield from (path[path_trim:] for path in full_paths) def copy(self, *, s3_object: S3Object, destination: str) -> S3Object: if self.path: