From 5aecfdc725da36fa98b6c7c650892b9ccebe8499 Mon Sep 17 00:00:00 2001 From: kloeffler95 Date: Sun, 11 Jan 2026 18:06:42 -0700 Subject: [PATCH 1/2] Adding a guard so that if the user uses a brand new S3 bucket with no contents a KeyError is not received when configuring backups. --- management/backup.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/management/backup.py b/management/backup.py index 8cc2b375..f135afe1 100755 --- a/management/backup.py +++ b/management/backup.py @@ -505,12 +505,10 @@ def list_target_files(config): from botocore.exceptions import ClientError # separate bucket from path in target - bucket = target.path[1:].split('/')[0] - path = '/'.join(target.path[1:].split('/')[1:]) + '/' - - # If no prefix is specified, set the path to '', otherwise boto won't list the files - if path == '/': - path = '' + bucket_path = target.path.lstrip('/') + bucket, _, path = bucket_path.partition('/') + if path and not path.endswith('/'): + path += '/' if bucket == "": msg = "Enter an S3 bucket name." @@ -525,10 +523,11 @@ def list_target_files(config): endpoint_url=f'https://{target.hostname}', \ aws_access_key_id=config['target_user'], \ aws_secret_access_key=config['target_pass']) - bucket_objects = s3.list_objects_v2(Bucket=bucket, Prefix=path)['Contents'] + response = s3.list_objects_v2(Bucket=bucket, Prefix=path) + bucket_objects = response.get('Contents', []) backup_list = [(key['Key'][len(path):], key['Size']) for key in bucket_objects] except ClientError as e: - raise ValueError(e) + raise ValueError(msg) return backup_list if target.scheme == 'b2': from b2sdk.v1 import InMemoryAccountInfo, B2Api From 64fdeec0fe8a1277206fc0a7f6a685c8e43caac6 Mon Sep 17 00:00:00 2001 From: kloeffler95 Date: Sun, 11 Jan 2026 18:09:58 -0700 Subject: [PATCH 2/2] Fixing erroneously changed variable name. --- management/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/management/backup.py b/management/backup.py index f135afe1..329215eb 100755 --- a/management/backup.py +++ b/management/backup.py @@ -527,7 +527,7 @@ def list_target_files(config): bucket_objects = response.get('Contents', []) backup_list = [(key['Key'][len(path):], key['Size']) for key in bucket_objects] except ClientError as e: - raise ValueError(msg) + raise ValueError(e) return backup_list if target.scheme == 'b2': from b2sdk.v1 import InMemoryAccountInfo, B2Api