File tree Expand file tree Collapse file tree 1 file changed +6
-11
lines changed
cosmotech/coal/cli/commands Expand file tree Collapse file tree 1 file changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -94,20 +94,15 @@ def s3_bucket_delete(
9494
9595 s3_resource = boto3 .resource ("s3" ,
9696 ** boto3_parameters )
97-
9897 bucket = s3_resource .Bucket (bucket_name )
9998
100- remove_prefix = False
10199 if file_prefix :
102100 bucket_files = bucket .objects .filter (Prefix = file_prefix )
103- if file_prefix .endswith ("/" ):
104- remove_prefix = True
105101 else :
106102 bucket_files = bucket .objects .all ()
107- for _file in bucket_files :
108- if not (path_name := str (_file .key )).endswith ("/" ):
109- target_file = path_name
110- if remove_prefix :
111- target_file = target_file .removeprefix (file_prefix )
112- LOGGER .info (f"Deleting { path_name } " )
113- bucket .delete_key (_file .key )
103+
104+ boto_objects = [{'Key' : _file .key } for _file in bucket_files if _file .key != file_prefix ]
105+ if boto_objects :
106+ LOGGER .info (f'Deleting { boto_objects } ' )
107+ boto_delete_request = {'Objects' : boto_objects }
108+ bucket .delete_objects (Delete = boto_delete_request )
You can’t perform that action at this time.
0 commit comments