Skip to content

Commit

Permalink
Infra: introduce retry func warpper
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Sep 12, 2024
1 parent 99bb24f commit dccf634
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,25 +456,25 @@ def mkdir(self, path: str, create_parents: bool = True, **kwargs: Any) -> None:
if not key:
raise TosfsError(f"Cannot create a bucket {bucket} using mkdir api.")

try:
if create_parents:
parent = self._parent(f"{bucket}/{key}".rstrip("/") + "/")
if not self.exists(parent):
# here we need to create the parent directory recursively
self.mkdir(parent, create_parents=True)
self.tos_client.put_object(bucket, key.rstrip("/") + "/")
if create_parents:
parent = self._parent(f"{bucket}/{key}".rstrip("/") + "/")
if not self.exists(parent):
# here we need to create the parent directory recursively
self.mkdir(parent, create_parents=True)

retryable_func(
lambda: self.tos_client.put_object(bucket, key.rstrip("/") + "/"),
max_retry_num=self.max_retry_num,
)
else:
parent = self._parent(path)
if not self.exists(parent):
raise FileNotFoundError(f"Parent directory {parent} does not exist.")
else:
parent = self._parent(path)
if not self.exists(parent):
raise FileNotFoundError(
f"Parent directory {parent} does not exist."
)
else:
self.tos_client.put_object(bucket, key.rstrip("/") + "/")
except (TosClientError, TosServerError, FileNotFoundError) as e:
raise e
except Exception as e:
raise TosfsError(f"Tosfs failed with unknown error: {e}") from e
retryable_func(
self.tos_client.put_object(bucket, key.rstrip("/") + "/"),
max_retry_num=self.max_retry_num,
)

def makedirs(self, path: str, exist_ok: bool = False) -> None:
"""Recursively make directories.
Expand Down

0 comments on commit dccf634

Please sign in to comment.