Skip to content

Commit 7fde50a

Browse files
TomNicholasclaude
andcommitted
Fix list_dir prefix stripping: use removeprefix instead of lstrip
lstrip strips individual characters from the given set, not a prefix string. This corrupted directory names when the prefix shared characters with child names (e.g. "temp" → "emp" when prefix contained "t"). Fixes zarr-developers#3753 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 690be1e commit 7fde50a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/zarr/storage/_obstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ async def _transform_list_dir(
260260
# We assume that the underlying object-store implementation correctly handles the
261261
# prefix, so we don't double-check that the returned results actually start with the
262262
# given prefix.
263-
prefixes = [obj.lstrip(prefix).lstrip("/") for obj in list_result["common_prefixes"]]
263+
prefixes = [obj.removeprefix(prefix).lstrip("/") for obj in list_result["common_prefixes"]]
264264
objects = [obj["path"].removeprefix(prefix).lstrip("/") for obj in list_result["objects"]]
265265
for item in prefixes + objects:
266266
yield item

0 commit comments

Comments
 (0)