@@ -97,6 +97,7 @@ def upload_file(self, file_name, cloud_name, permissions):
9797 source_bucket = None ,
9898 destination_bucket = None ,
9999 overwrite = True ,
100+ copy_metadata = False ,
100101 )
101102
102103 def upload_multipart (self , stream , cloud_name , metadata , permissions ,
@@ -219,7 +220,7 @@ def list_objects(self, **kwargs):
219220 return results
220221
221222 def copy (self , source , destination , source_bucket , destination_bucket ,
222- overwrite ):
223+ overwrite , copy_metadata = True ):
223224 """Copies an object
224225
225226 Parameters
@@ -232,6 +233,9 @@ def copy(self, source, destination, source_bucket, destination_bucket,
232233 destination_bucket : ignored
233234 overwrite : bool
234235 overwrite if destination exists
236+ copy_metadata : bool
237+ also copy metadata file? (we don't want to do this if copying from
238+ the local filesystem)
235239
236240 Returns
237241 -------
@@ -245,6 +249,11 @@ def copy(self, source, destination, source_bucket, destination_bucket,
245249 destination_bucket = source_bucket
246250 source = os .path .join (source_bucket , source )
247251 destination = os .path .join (destination_bucket , destination )
252+ if copy_metadata :
253+ source_metadata = os .path .join (source_bucket , source + METADATA_SUFFIX )
254+ destination_metadata = os .path .join (destination_bucket , destination + METADATA_SUFFIX )
255+ shutil .copy (source_metadata , destination_metadata )
256+
248257 auto_makedirs (destination )
249258 return shutil .copy (source , destination )
250259
@@ -272,8 +281,10 @@ def move(self, source, destination, source_bucket, destination_bucket,
272281 destination_bucket = source_bucket
273282 source = os .path .join (source_bucket , source )
274283 destination = os .path .join (destination_bucket , destination )
284+ source_metadata = os .path .join (source_bucket , source + METADATA_SUFFIX )
285+ destination_metadata = os .path .join (destination_bucket , destination + METADATA_SUFFIX )
275286 auto_makedirs (destination )
276- return shutil .move (source , destination )
287+ return shutil .move (source , destination ) and shutil . move ( source_metadata , destination_metadata )
277288
278289 def delete (self , cloud_name , recursive = False , delete = False ):
279290 """Deletes an object
@@ -294,6 +305,9 @@ def delete(self, cloud_name, recursive=False, delete=False):
294305 cloud_name = os .path .join (self .path , cloud_name )
295306 if os .path .isfile (cloud_name ):
296307 os .remove (cloud_name )
308+ cloud_metadata_name = cloud_name + METADATA_SUFFIX
309+ if os .path .isfile (cloud_metadata_name ):
310+ os .remove (cloud_metadata_name )
297311 else :
298312 if recursive :
299313 shutil .rmtree (cloud_name )
0 commit comments