Skip to content

Commit

Permalink
Classification different methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Sep 26, 2024
1 parent 3154333 commit 2f7b088
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def exists(self, path: str, **kwargs: Any) -> bool:
lambda: self.tos_client.head_object(
bucket, key.rstrip("/") + "/"
)
or True,
or True,
max_retry_num=self.max_retry_num,
)
except TosServerError as ex:
Expand All @@ -543,7 +543,7 @@ def exists(self, path: str, **kwargs: Any) -> bool:
key.rstrip("/") + "/",
start_after=key.rstrip("/") + "/",
max_keys=1,
),
),
max_retry_num=self.max_retry_num,
)
return len(resp.contents) > 0
Expand Down Expand Up @@ -590,10 +590,7 @@ def rmdir(self, path: str) -> None:
if not self.isdir(path):
raise NotADirectoryError(f"{path} is not a directory.")

if (
len(self._ls_objects(bucket, max_items=1, prefix=key.rstrip("/") + "/"))
> 0
):
if len(self._ls_objects(bucket, max_items=1, prefix=key.rstrip("/") + "/")) > 0:
raise TosfsError(f"Directory {path} is not empty.")

retryable_func_executor(
Expand Down Expand Up @@ -1024,7 +1021,6 @@ def walk(
path, maxdepth=maxdepth, topdown=topdown, on_error=on_error, **kwargs
)


def find(
self,
path: str,
Expand Down Expand Up @@ -1084,7 +1080,6 @@ def find(
else:
return [o["name"] for o in out]


def expand_path(
self,
path: Union[str, List[str]],
Expand Down Expand Up @@ -1312,7 +1307,7 @@ def _rm(self, path: str) -> None:
except Exception as e:
raise TosfsError(f"Tosfs failed with unknown error: {e}") from e

######################## private methods ########################
######################## private methods ########################

def _list_and_batch_delete_objs(self, bucket: str, key: str) -> None:
is_truncated = True
Expand Down Expand Up @@ -2012,15 +2007,15 @@ def _fill_bucket_info(bucket_name: str) -> dict:
"name": bucket_name,
}

###### fsspec's api implements (for old version compatibility) ######
###### fsspec's api implements (for old version compatibility) ######

def _fsspec_walk( # noqa
self,
path: str,
maxdepth: Optional[int] = None,
topdown: bool = True,
on_error: str = "omit",
**kwargs: Any,
self,
path: str,
maxdepth: Optional[int] = None,
topdown: bool = True,
on_error: str = "omit",
**kwargs: Any,
) -> Any:
"""Return all files belows path.
Expand Down Expand Up @@ -2122,12 +2117,12 @@ def _fsspec_walk( # noqa
yield path, dirs, files

def _fsspec_find( # noqa #
self,
path: str,
maxdepth: Optional[int] = None,
withdirs: bool = False,
detail: bool = False,
**kwargs: Any, # type: ignore
self,
path: str,
maxdepth: Optional[int] = None,
withdirs: bool = False,
detail: bool = False,
**kwargs: Any, # type: ignore
) -> Any:
"""List all files below path.
Expand Down

0 comments on commit 2f7b088

Please sign in to comment.