Skip to content

Commit

Permalink
Address review concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Aug 20, 2024
1 parent 1ba8d8a commit 09789a0
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ def rmdir(self, path: str) -> None:
path = self._strip_protocol(path).rstrip("/") + "/"
bucket, key, _ = self._split_path(path)
if not key:
return self._rm_bucket(path)
logger.error("Cannot remove a bucket using rmdir api.")
raise TosfsError("Cannot remove a bucket using rmdir api.")

if not self.exists(path):
raise FileNotFoundError(f"Directory {path} not found.")
Expand All @@ -255,35 +256,6 @@ def rmdir(self, path: str) -> None:
logger.error("Tosfs failed with unknown error: %s", e)
raise TosfsError(f"Tosfs failed with unknown error: {e}") from e

def _rm_bucket(self, path: str) -> None:
"""Remove a bucket."""
bucket, _, _ = self._split_path(path)

try:
# if the bucket is not empty, raise an error
if len(self.ls(bucket, refresh=True, detail=False)) > 0:
logger.warning(
"Try to delete bucket %s, "
"but delete failed due to bucket is not empty.",
bucket,
)
raise TosfsError(f"Bucket {bucket} is not empty.")

logger.warning("Deleting an empty bucket %s", bucket)
self.tos_client.delete_bucket(bucket)
except tos.exceptions.TosClientError as e:
logger.error("Tosfs failed with client error: %s", e)
raise e
except tos.exceptions.TosServerError as e:
logger.error("Tosfs failed with server error: %s", e)
raise e
except Exception as e:
logger.error("Tosfs failed with unknown error: %s", e)
raise TosfsError(f"Tosfs failed with unknown error: {e}") from e

self.invalidate_cache(path.rstrip("/"))
self.invalidate_cache("")

def _info_from_cache(
self, path: str, fullpath: str, version_id: Optional[str]
) -> dict:
Expand Down

0 comments on commit 09789a0

Please sign in to comment.