Skip to content

Commit

Permalink
Correct rmdir when not just a bucket (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Sep 22, 2023
1 parent 7e05807 commit b4b9fb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,13 @@ async def _makedirs(self, path, exist_ok=False):
makedirs = sync_wrapper(_makedirs)

async def _rmdir(self, path):
bucket, key, _ = self.split_path(path)
if key:
if await self._exists(path):
# User may have meant rm(path, recursive=True)
raise FileExistsError
raise FileNotFoundError

try:
await self._call_s3("delete_bucket", Bucket=path)
except botocore.exceptions.ClientError as e:
Expand Down
16 changes: 16 additions & 0 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,22 @@ def test_rmdir(s3):
s3.rmdir(bucket)
assert bucket not in s3.ls("/")

# Issue 689, s3fs rmdir command returns error when given a valid s3 path.
dir = test_bucket_name + "/dir"

assert not s3.exists(dir)
with pytest.raises(FileNotFoundError):
s3.rmdir(dir)

s3.touch(dir + "/file")
assert s3.exists(dir)
assert s3.exists(dir + "/file")
with pytest.raises(FileExistsError):
s3.rmdir(dir)

with pytest.raises(OSError):
s3.rmdir(test_bucket_name)


def test_mkdir(s3):
bucket = "test1_bucket"
Expand Down

0 comments on commit b4b9fb2

Please sign in to comment.