Skip to content

Commit 749c861

Browse files
slowjazzmeeseeksmachine
authored andcommitted
Backport PR zarr-developers#3310: obstore delete_dir
1 parent 8b00b94 commit 749c861

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

changes/3310.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add obstore implementation of delete_dir.

src/zarr/storage/_obstore.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Store,
1414
SuffixByteRequest,
1515
)
16+
from zarr.core.common import concurrent_map
1617
from zarr.core.config import config
1718

1819
if TYPE_CHECKING:
@@ -196,6 +197,18 @@ async def delete(self, key: str) -> None:
196197
with contextlib.suppress(FileNotFoundError):
197198
await obs.delete_async(self.store, key)
198199

200+
async def delete_dir(self, prefix: str) -> None:
201+
# docstring inherited
202+
import obstore as obs
203+
204+
self._check_writable()
205+
if prefix != "" and not prefix.endswith("/"):
206+
prefix += "/"
207+
208+
metas = await obs.list(self.store, prefix).collect_async()
209+
keys = [(m["path"],) for m in metas]
210+
await concurrent_map(keys, self.delete, limit=config.get("async.concurrency"))
211+
199212
@property
200213
def supports_partial_writes(self) -> bool:
201214
# docstring inherited

0 commit comments

Comments
 (0)