From 36a4b5f2165d3c88d71e87e6e9d9bb88f52c06df Mon Sep 17 00:00:00 2001 From: yanghua Date: Tue, 12 Nov 2024 15:14:52 +0800 Subject: [PATCH] Run test cases on hns --- tosfs/core.py | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/tosfs/core.py b/tosfs/core.py index 184177a..81b875d 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -59,7 +59,7 @@ from tosfs.mpu import MultipartUploader from tosfs.retry import CONFLICT_CODE, INVALID_RANGE_CODE, retryable_func_executor from tosfs.tag import BucketTagMgr -from tosfs.utils import find_bucket_key, get_brange, is_dir +from tosfs.utils import find_bucket_key, get_brange from tosfs.version import Version logger = logging.getLogger("tosfs") @@ -835,32 +835,22 @@ def isdir(self, path: str) -> bool: if not key: return False - key = key.rstrip("/") + "/" - try: - resp = retryable_func_executor( - lambda: self.tos_client.get_file_status(bucket, key), - max_retry_num=self.max_retry_num, - ) - return resp.key is not None and is_dir(resp.key, key) + if self._is_fns_bucket(bucket): + resp = retryable_func_executor( + lambda: self.tos_client.get_file_status(bucket, key), + max_retry_num=self.max_retry_num, + ) + return resp.key != key + else: + resp = retryable_func_executor( + lambda: self.tos_client.head_object(bucket, key), + max_retry_num=self.max_retry_num, + ) + return resp.is_directory except TosServerError as e: if e.status_code == TOS_SERVER_STATUS_CODE_NOT_FOUND: return False - if ( - self._get_bucket_type(bucket) == TOS_BUCKET_TYPE_HNS - and e.status_code == CONFLICT_CODE - and e.header._store["x-tos-ec"][1] == "0026-00000020" - ): - out = retryable_func_executor( - lambda: self.tos_client.list_objects_type2( - bucket, - prefix=key, - delimiter="/", - max_keys=1, - ), - max_retry_num=self.max_retry_num, - ) - return out.key_count > 0 raise e def isfile(self, path: str) -> bool: