Skip to content

Commit

Permalink
report on list of keys deleted in bulk (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed Apr 14, 2023
1 parent aece3ec commit 39d8165
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,12 @@ async def _bulk_delete(self, pathlist, **kwargs):
}
for path in pathlist:
self.invalidate_cache(self._parent(path))
await self._call_s3("delete_objects", kwargs, Bucket=bucket, Delete=delete_keys)
out = await self._call_s3(
"delete_objects", kwargs, Bucket=bucket, Delete=delete_keys
)
# TODO: we report on successes but don't raise on any errors, effectively
# on_error="omit"
return [f"{bucket}/{_['Key']}" for _ in out.get("Deleted", [])]

async def _rm_file(self, path, **kwargs):
bucket, key, _ = self.split_path(path)
Expand All @@ -1861,7 +1866,7 @@ async def _rm(self, path, recursive=False, **kwargs):
files = [p for p in paths if self.split_path(p)[1]]
dirs = [p for p in paths if not self.split_path(p)[1]]
# TODO: fails if more than one bucket in list
await _run_coros_in_chunks(
out = await _run_coros_in_chunks(
[
self._bulk_delete(files[i : i + 1000])
for i in range(0, len(files), 1000)
Expand All @@ -1874,6 +1879,7 @@ async def _rm(self, path, recursive=False, **kwargs):
(self.invalidate_cache(p), self.invalidate_cache(self._parent(p)))
for p in paths
]
return sum(out, [])

async def _is_bucket_versioned(self, bucket):
return (await self._call_s3("get_bucket_versioning", Bucket=bucket)).get(
Expand Down
6 changes: 4 additions & 2 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,13 @@ def test_rm(s3):
# s3.rm(test_bucket_name + '/nonexistent')
with pytest.raises(FileNotFoundError):
s3.rm("nonexistent")
s3.rm(test_bucket_name + "/nested", recursive=True)
out = s3.rm(test_bucket_name + "/nested", recursive=True)
assert test_bucket_name + "/nested/nested2/file1" in out
assert not s3.exists(test_bucket_name + "/nested/nested2/file1")

# whole bucket
s3.rm(test_bucket_name, recursive=True)
out = s3.rm(test_bucket_name, recursive=True)
assert test_bucket_name + "/2014-01-01.csv" in out
assert not s3.exists(test_bucket_name + "/2014-01-01.csv")
assert not s3.exists(test_bucket_name)

Expand Down

0 comments on commit 39d8165

Please sign in to comment.