Skip to content

Commit

Permalink
Don't trim paths in list_file if class initialized with no path
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DHUKK committed Aug 29, 2024
1 parent 95c43e7 commit e648e6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 0 additions & 1 deletion tests/storage/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion xocto/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e648e6f

Please sign in to comment.