Browse code

move empty object name detection where it belongs

Commit 9679f269 added empty object name detection. But that was done
"too far down" - it needs to be done when the list is first read from
S3, not later every time the list is iterated.

Matt Domsch authored on 2014/02/22 10:45:10
Showing 2 changed files
... ...
@@ -354,6 +354,7 @@ def fetch_remote_list(args, require_attribs = False, recursive = None):
354 354
         ## { 'xyz/blah.txt' : {} }
355 355
 
356 356
         info(u"Retrieving list of remote files for %s ..." % remote_uri)
357
+        empty_fname_re = re.compile(r'\A\s*\Z')
357 358
 
358 359
         s3 = S3(Config())
359 360
         response = s3.bucket_list(remote_uri.bucket(), prefix = remote_uri.object(), recursive = recursive)
... ...
@@ -376,6 +377,10 @@ def fetch_remote_list(args, require_attribs = False, recursive = None):
376 376
             else:
377 377
                 key = object['Key'][rem_base_len:]      ## Beware - this may be '' if object['Key']==rem_base !!
378 378
                 object_uri_str = remote_uri.uri() + key
379
+            if empty_fname_re.match(key):
380
+                # Objects may exist on S3 with empty names (''), which don't map so well to common filesystems.
381
+                warning(u"Empty object name on S3 found, ignoring.")
382
+                continue
379 383
             rem_list[key] = {
380 384
                 'size' : int(object['Size']),
381 385
                 'timestamp' : dateS3toUnix(object['LastModified']), ## Sadly it's upload time, not our lastmod time :-(
... ...
@@ -844,7 +844,6 @@ def cmd_sync_remote2local(args):
844 844
 
845 845
     info(u"Summary: %d remote files to download, %d local files to delete, %d local files to hardlink" % (remote_count + update_count, local_count, copy_pairs_count))
846 846
 
847
-    empty_fname_re = re.compile(r'\A\s*\Z')
848 847
     def _set_local_filename(remote_list, destination_base):
849 848
         keys_to_remove = []
850 849
         if len(remote_list) == 0:
... ...
@@ -858,11 +857,6 @@ def cmd_sync_remote2local(args):
858 858
             if destination_base[-1] != os.path.sep:
859 859
                 destination_base += os.path.sep
860 860
             for key in remote_list:
861
-                if empty_fname_re.match(key):
862
-                    # Objects may exist on S3 with empty names (''), which don't map so well to common filesystems.
863
-                    warning(u"Empty object name on S3 found, ignoring.")
864
-                    keys_to_remove.append(key)
865
-                    continue
866 861
                 local_filename = destination_base + key
867 862
                 if os.path.sep != "/":
868 863
                     local_filename = os.path.sep.join(local_filename.split("/"))