Skip to content

Commit a7d66a4

Browse files
authored
Merge pull request #141 from ligangty/main
Fix: handle file exists check exception
2 parents 3810d11 + eca4b0e commit a7d66a4

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

charon/pkgs/maven.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,15 @@ def _generate_rollback_archetype_catalog(
658658

659659
# If there is no local catalog, this is a NO-OP
660660
if os.path.exists(local):
661-
if not s3.file_exists_in_bucket(bucket, remote):
661+
existed = False
662+
try:
663+
existed = s3.file_exists_in_bucket(bucket, remote)
664+
except ValueError as e:
665+
logger.error(
666+
"Error: Can not generate archtype-catalog.xml due to: %s", e
667+
)
668+
return 0
669+
if not existed:
662670
# If there is no catalog in the bucket...this is a NO-OP
663671
return 0
664672
else:
@@ -758,7 +766,15 @@ def _generate_upload_archetype_catalog(
758766

759767
# If there is no local catalog, this is a NO-OP
760768
if os.path.exists(local):
761-
if not s3.file_exists_in_bucket(bucket, remote):
769+
existed = False
770+
try:
771+
existed = s3.file_exists_in_bucket(bucket, remote)
772+
except ValueError as e:
773+
logger.error(
774+
"Error: Can not generate archtype-catalog.xml due to: %s", e
775+
)
776+
return 0
777+
if not existed:
762778
__gen_all_digest_files(local)
763779
# If there is no catalog in the bucket, just upload what we have locally
764780
return True

charon/storage.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ async def path_upload_handler(
148148

149149
path_key = os.path.join(key_prefix, path) if key_prefix else path
150150
file_object: s3.Object = bucket.Object(path_key)
151-
existed = await self.__run_async(self.__file_exists, file_object)
151+
existed = False
152+
try:
153+
existed = await self.__run_async(self.__file_exists, file_object)
154+
except (ClientError, HTTPClientError) as e:
155+
logger.error(
156+
"Error: file existence check failed due to error: %s", e
157+
)
158+
failed.append(full_file_path)
159+
return
152160
sha1 = read_sha1(full_file_path)
153161
(content_type, _) = mimetypes.guess_type(full_file_path)
154162
if not content_type:
@@ -262,7 +270,15 @@ async def path_upload_handler(
262270

263271
path_key = os.path.join(key_prefix, path) if key_prefix else path
264272
file_object: s3.Object = bucket.Object(path_key)
265-
existed = await self.__run_async(self.__file_exists, file_object)
273+
existed = False
274+
try:
275+
existed = await self.__run_async(self.__file_exists, file_object)
276+
except (ClientError, HTTPClientError) as e:
277+
logger.error(
278+
"Error: file existence check failed due to error: %s", e
279+
)
280+
failed.append(full_file_path)
281+
return
266282
f_meta = {}
267283
need_overwritten = True
268284
sha1 = read_sha1(full_file_path)
@@ -367,7 +383,15 @@ async def path_delete_handler(
367383
logger.debug('(%d/%d) Deleting %s from bucket %s', index, total, path, bucket_name)
368384
path_key = os.path.join(key_prefix, path) if key_prefix else path
369385
file_object = bucket.Object(path_key)
370-
existed = await self.__run_async(self.__file_exists, file_object)
386+
existed = False
387+
try:
388+
existed = await self.__run_async(self.__file_exists, file_object)
389+
except (ClientError, HTTPClientError) as e:
390+
logger.error(
391+
"Error: file existence check failed due to error: %s", e
392+
)
393+
failed.append(full_file_path)
394+
return
371395
if existed:
372396
# NOTE: If we're NOT using the product key to track collisions
373397
# (in the case of metadata), then this prods array will remain
@@ -458,7 +482,15 @@ def delete_manifest(self, product_key: str, target: str, manifest_bucket_name: s
458482

459483
manifest_bucket = self.__get_bucket(manifest_bucket_name)
460484
file_object: s3.Object = manifest_bucket.Object(path_key)
461-
if self.__file_exists(file_object):
485+
existed = False
486+
try:
487+
existed = self.__file_exists(file_object)
488+
except (ClientError, HTTPClientError) as e:
489+
logger.error(
490+
"Error: file existence check failed due to error: %s", e
491+
)
492+
return
493+
if existed:
462494
manifest_bucket.delete_objects(Delete={"Objects": [{"Key": path_key}]})
463495
else:
464496
logger.warning(
@@ -555,8 +587,7 @@ def __file_exists(self, file_object: Object) -> bool:
555587
if isinstance(e, ClientError) and e.response["Error"]["Code"] == "404":
556588
return False
557589
else:
558-
logger.error("Error: file existence check failed due "
559-
"to error: %s", e)
590+
raise e
560591

561592
def __get_prod_info(
562593
self, file: str, bucket_name: str

0 commit comments

Comments
 (0)