Browse code

When using --no-preserve, still add 'md5' custom attribute if md5 check is enabled.

Florent Viard authored on 2015/11/27 02:36:17
Showing 1 changed files
... ...
@@ -376,10 +376,9 @@ def cmd_object_put(args):
376 376
         seq_label = "[%d of %d]" % (seq, local_count)
377 377
         if Config().encrypt:
378 378
             gpg_exitcode, full_name, extra_headers["x-amz-meta-s3tools-gpgenc"] = gpg_encrypt(full_name_orig)
379
-        if cfg.preserve_attrs or local_list[key]['size'] > (cfg.multipart_chunk_size_mb * 1024 * 1024):
380
-            attr_header = _build_attr_header(local_list, key)
381
-            debug(u"attr_header: %s" % attr_header)
382
-            extra_headers.update(attr_header)
379
+        attr_header = _build_attr_header(local_list, key)
380
+        debug(u"attr_header: %s" % attr_header)
381
+        extra_headers.update(attr_header)
383 382
         try:
384 383
             response = s3.object_put(full_name, uri_final, extra_headers, extra_label = seq_label)
385 384
         except S3UploadError, exc:
... ...
@@ -1469,42 +1468,47 @@ def remote_copy(s3, copy_pairs, destination_base):
1469 1469
 
1470 1470
 def _build_attr_header(local_list, src):
1471 1471
     attrs = {}
1472
-    for attr in cfg.preserve_attrs_list:
1473
-        if attr == 'uname':
1474
-            try:
1475
-                val = Utils.getpwuid_username(local_list[src]['uid'])
1476
-            except (KeyError, TypeError):
1477
-                attr = "uid"
1478
-                val = local_list[src].get('uid')
1479
-                if val:
1480
-                    warning(u"%s: Owner username not known. Storing UID=%d instead." % (src, val))
1481
-        elif attr == 'gname':
1482
-            try:
1483
-                val = Utils.getgrgid_grpname(local_list[src].get('gid'))
1484
-            except (KeyError, TypeError):
1485
-                attr = "gid"
1486
-                val = local_list[src].get('gid')
1487
-                if val:
1488
-                    warning(u"%s: Owner groupname not known. Storing GID=%d instead." % (src, val))
1489
-        elif attr == 'md5':
1490
-            try:
1491
-                val = local_list.get_md5(src)
1492
-            except IOError:
1493
-                val = None
1494
-        else:
1495
-            try:
1496
-                val = getattr(local_list[src]['sr'], 'st_' + attr)
1497
-            except:
1498
-                val = None
1499
-        if val is not None:
1500
-            attrs[attr] = val
1472
+    if cfg.preserve_attrs:
1473
+        for attr in cfg.preserve_attrs_list:
1474
+            if attr == 'uname':
1475
+                try:
1476
+                    val = Utils.getpwuid_username(local_list[src]['uid'])
1477
+                except (KeyError, TypeError):
1478
+                    attr = "uid"
1479
+                    val = local_list[src].get('uid')
1480
+                    if val:
1481
+                        warning(u"%s: Owner username not known. Storing UID=%d instead." % (src, val))
1482
+            elif attr == 'gname':
1483
+                try:
1484
+                    val = Utils.getgrgid_grpname(local_list[src].get('gid'))
1485
+                except (KeyError, TypeError):
1486
+                    attr = "gid"
1487
+                    val = local_list[src].get('gid')
1488
+                    if val:
1489
+                        warning(u"%s: Owner groupname not known. Storing GID=%d instead." % (src, val))
1490
+            elif attr != "md5":
1491
+                try:
1492
+                    val = getattr(local_list[src]['sr'], 'st_' + attr)
1493
+                except:
1494
+                    val = None
1495
+            if val is not None:
1496
+                attrs[attr] = val
1501 1497
 
1502
-    if 'md5' in attrs and attrs['md5'] is None:
1503
-        del attrs['md5']
1498
+    if 'md5' in cfg.preserve_attrs_list:
1499
+        try:
1500
+            val = local_list.get_md5(src)
1501
+            if val is not None:
1502
+                attrs['md5'] = val
1503
+        except IOError:
1504
+            pass
1504 1505
 
1505
-    result = ""
1506
-    for k in attrs: result += "%s:%s/" % (k, attrs[k])
1507
-    return { 'x-amz-meta-s3cmd-attrs' : result[:-1] }
1506
+    if attrs:
1507
+        result = ""
1508
+        for k in attrs:
1509
+            result += "%s:%s/" % (k, attrs[k])
1510
+        return {'x-amz-meta-s3cmd-attrs' : result[:-1]}
1511
+    else:
1512
+        return {}
1508 1513
 
1509 1514
 
1510 1515
 def cmd_sync_local2remote(args):
... ...
@@ -1568,10 +1572,9 @@ def cmd_sync_local2remote(args):
1568 1568
                 seq_label = "[%d of %d]" % (seq, total)
1569 1569
                 extra_headers = copy(cfg.extra_headers)
1570 1570
                 try:
1571
-                    if cfg.preserve_attrs:
1572
-                        attr_header = _build_attr_header(local_list, file)
1573
-                        debug(u"attr_header: %s" % attr_header)
1574
-                        extra_headers.update(attr_header)
1571
+                    attr_header = _build_attr_header(local_list, file)
1572
+                    debug(u"attr_header: %s" % attr_header)
1573
+                    extra_headers.update(attr_header)
1575 1574
                     response = s3.object_put(src, uri, extra_headers, extra_label = seq_label)
1576 1575
                 except S3UploadError, exc:
1577 1576
                     error(u"Upload of '%s' failed too many times (Last reason: %s)" % (item['full_name'], exc))