Skip to content

Commit 20e8864

Browse files
author
Rakshil Modi
committed
Modifying S3 Handler
1 parent a8c88b5 commit 20e8864

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

awscli/customizations/s3/s3handler.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
relative_path,
5858
split_s3_bucket_key,
5959
)
60+
from awscli.customizations.utils import uni_print
6061
from awscli.s3transfer.constants import MAX_BATCH_SIZE
6162

6263
LOGGER = logging.getLogger(__name__)
@@ -832,11 +833,10 @@ def _submit_transfer_request_for_batch(self, batches):
832833
future = self._transfer_manager.batch_delete(
833834
bucket=bucket, objects=objects, extra_args=extra_args
834835
)
835-
future.result()
836-
837-
# Report success
838-
for fileinfo in fileinfos_in_batch:
839-
self._report_success(fileinfo)
836+
response = future.result()
837+
self._handle_batch_delete_response(
838+
response, fileinfos_in_batch
839+
)
840840

841841
except Exception as e:
842842
for fileinfo in fileinfos_in_batch:
@@ -865,3 +865,23 @@ def _format_src_dest(self, fileinfo):
865865
if hasattr(fileinfo, 'version_id') and fileinfo.version_id:
866866
src = f"{src} (version {fileinfo.version_id})"
867867
return src, None
868+
869+
def _report_error(self, fileinfo, error_message):
870+
src, _ = self._format_src_dest(fileinfo)
871+
uni_print(f"delete failed: {src} - {error_message}\n")
872+
873+
def _handle_batch_delete_response(self, response, fileinfos_in_batch):
874+
error_objects = {}
875+
for error in response.get('Errors', []):
876+
key = error['Key']
877+
version_id = error.get('VersionId', None)
878+
error_objects[(key, version_id)] = error['Message']
879+
880+
for fileinfo in fileinfos_in_batch:
881+
_, key = split_s3_bucket_key(fileinfo.src)
882+
if (key, fileinfo.version_id) in error_objects:
883+
self._report_error(
884+
fileinfo, error_objects[(key, fileinfo.version_id)]
885+
)
886+
else:
887+
self._report_success(fileinfo)

0 commit comments

Comments
 (0)