From 54cf5bda519243579d50f5008ad4d647c49cd915 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Wed, 28 Feb 2024 20:05:14 +0800 Subject: [PATCH] Fix a bug for re-index Found that if prefix is "/" in target will cause some missing in path for re-index. Fixed here --- charon/pkgs/indexing.py | 13 +++++++------ charon/storage.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/charon/pkgs/indexing.py b/charon/pkgs/indexing.py index 2c840b47..0ab43057 100644 --- a/charon/pkgs/indexing.py +++ b/charon/pkgs/indexing.py @@ -269,7 +269,8 @@ def re_index( """Refresh the index.html for the specified folder in the bucket. """ s3_client = S3Client(aws_profile=aws_profile, dry_run=dry_run) - s3_folder = os.path.join(prefix, path) + real_prefix = prefix if prefix.strip() != "/" else "" + s3_folder = os.path.join(real_prefix, path) if path.strip() == "" or path.strip() == "/": s3_folder = prefix items: List[str] = s3_client.list_folder_content(bucket, s3_folder) @@ -285,11 +286,11 @@ def re_index( if len(contents) >= 1: real_contents = [] - if prefix and prefix.strip() != "": + if real_prefix and real_prefix.strip() != "": for c in contents: if c.strip() != "": - if c.startswith(prefix): - real_c = remove_prefix(c, prefix) + if c.startswith(real_prefix): + real_c = remove_prefix(c, real_prefix) real_c = remove_prefix(real_c, "/") real_contents.append(real_c) else: @@ -302,9 +303,9 @@ def re_index( index_path = os.path.join(path, "index.html") if path == "/": index_path = "index.html" - s3_client.simple_delete_file(index_path, (bucket, prefix)) + s3_client.simple_delete_file(index_path, (bucket, real_prefix)) s3_client.simple_upload_file( - index_path, index_content, (bucket, prefix), + index_path, index_content, (bucket, real_prefix), "text/html", digest_content(index_content) ) else: diff --git a/charon/storage.py b/charon/storage.py index f07b1c50..68b73a32 100644 --- a/charon/storage.py +++ b/charon/storage.py @@ -713,7 +713,7 @@ def simple_upload_file( Metadata=f_meta, ContentType=content_type ) - logger.debug('Uploaded %s to bucket %s', file_path, bucket) + logger.debug('Uploaded %s to bucket %s', path_key, bucket) except (ClientError, HTTPClientError) as e: logger.error( "ERROR: file %s not uploaded to bucket %s due to error: %s ",