Quellcode durchsuchen

Fix listing files in empty bucket

DricomDragon vor 4 Jahren
Ursprung
Commit
fd7e3595fa
1 geänderte Dateien mit 5 neuen und 1 gelöschten Zeilen
  1. 5 1
      boto-updater.py

+ 5 - 1
boto-updater.py

@@ -19,7 +19,11 @@ except ClientError as e:
 # Get file list
 # Source : https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory
 local_file_list = os.listdir(folder_to_sync)
-bucket_file_list = [obj['Key'] for obj in s3.list_objects(Bucket=bucket_target)['Contents']]
+
+try:
+    bucket_file_list = [obj['Key'] for obj in s3.list_objects(Bucket=bucket_target)['Contents']]
+except:
+    bucket_file_list = [] # No key 'Contents' if empty bucket
 
 # Upload
 print("Uploading new files ...")