@@ -544,9 +544,12 @@ def _upload_to_s3(self, src, dst):
544
544
'''
545
545
546
546
# Import packages
547
+ import hashlib
547
548
import logging
548
549
import os
549
550
551
+ from botocore .exceptions import ClientError
552
+
550
553
# Init variables
551
554
bucket = self .bucket
552
555
iflogger = logging .getLogger ('interface' )
@@ -571,8 +574,26 @@ def _upload_to_s3(self, src, dst):
571
574
dst_f = dst_files [src_idx ]
572
575
dst_k = dst_f .replace (s3_prefix , '' ).lstrip ('/' )
573
576
577
+ # See if same file is already up there
578
+ try :
579
+ dst_obj = bucket .Object (key = dst_k )
580
+ dst_md5 = dst_obj .e_tag .strip ('"' )
581
+
582
+ # See if same file is already there
583
+ src_read = open (src_f , 'rb' ).read ()
584
+ src_md5 = hashlib .md5 (src_read ).hexdigest ()
585
+ # Move to next loop iteration
586
+ if dst_md5 == src_md5 :
587
+ iflogger .info ('File %s already exists on S3, skipping...' % dst_f )
588
+ continue
589
+ else :
590
+ iflogger .info ('Overwriting previous S3 file...' )
591
+
592
+ except ClientError as exc :
593
+ iflogger .info ('New file to S3' )
594
+
574
595
# Copy file up to S3 (either encrypted or not)
575
- iflogger .info ('Copying %s to S3 bucket, %s, as %s...' \
596
+ iflogger .info ('Uploading %s to S3 bucket, %s, as %s...' \
576
597
% (src_f , bucket .name , dst_f ))
577
598
if self .inputs .encrypt_bucket_keys :
578
599
extra_args = {'ServerSideEncryption' : 'AES256' }
0 commit comments