Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct rmdir when not just a bucket #795

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By doing this, we are explicitly not dealing with directory placeholder files. Perhaps that should be stated in the docstring.

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 @@ -621,6 +621,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