Browse code

Ignore S3 objects with empty names

Matt Domsch authored on 2014/02/15 03:43:50
Showing 1 changed files
... ...
@@ -846,6 +846,7 @@ def cmd_sync_remote2local(args):
846 846
 
847 847
     empty_fname_re = re.compile(r'\A\s*\Z')
848 848
     def _set_local_filename(remote_list, destination_base):
849
+        keys_to_remove = []
849 850
         if len(remote_list) == 0:
850 851
             return
851 852
         if not os.path.isdir(destination_base):
... ...
@@ -857,15 +858,17 @@ def cmd_sync_remote2local(args):
857 857
             if destination_base[-1] != os.path.sep:
858 858
                 destination_base += os.path.sep
859 859
             for key in remote_list:
860
-                local_basename = key
861 860
                 if empty_fname_re.match(key):
862 861
                     # Objects may exist on S3 with empty names (''), which don't map so well to common filesystems.
863
-                    local_basename = '__AWS-EMPTY-OBJECT-NAME__'
864
-                    warning(u"Empty object name on S3 found, saving locally as %s" % (local_basename))
865
-                local_filename = destination_base + local_basename
862
+                    warning(u"Empty object name on S3 found, ignoring.")
863
+                    keys_to_remove.append(key)
864
+                    continue
865
+                local_filename = destination_base + key
866 866
                 if os.path.sep != "/":
867 867
                     local_filename = os.path.sep.join(local_filename.split("/"))
868 868
                 remote_list[key]['local_filename'] = deunicodise(local_filename)
869
+            for key in keys_to_remove:
870
+                del remote_list[key]
869 871
 
870 872
     _set_local_filename(remote_list, destination_base)
871 873
     _set_local_filename(update_list, destination_base)