|
57 | 57 | relative_path,
|
58 | 58 | split_s3_bucket_key,
|
59 | 59 | )
|
| 60 | +from awscli.customizations.utils import uni_print |
60 | 61 | from awscli.s3transfer.constants import MAX_BATCH_SIZE
|
61 | 62 |
|
62 | 63 | LOGGER = logging.getLogger(__name__)
|
@@ -832,11 +833,10 @@ def _submit_transfer_request_for_batch(self, batches):
|
832 | 833 | future = self._transfer_manager.batch_delete(
|
833 | 834 | bucket=bucket, objects=objects, extra_args=extra_args
|
834 | 835 | )
|
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 | + ) |
840 | 840 |
|
841 | 841 | except Exception as e:
|
842 | 842 | for fileinfo in fileinfos_in_batch:
|
@@ -865,3 +865,23 @@ def _format_src_dest(self, fileinfo):
|
865 | 865 | if hasattr(fileinfo, 'version_id') and fileinfo.version_id:
|
866 | 866 | src = f"{src} (version {fileinfo.version_id})"
|
867 | 867 | 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