@@ -426,21 +426,39 @@ async def check_file(self, drive_name, path):
426426
427427 return
428428
429- async def copy_file (self , drive_name , path , to_path ):
429+ async def copy_file (self , drive_name , path , to_path , to_drive ):
430430 """Save file with new content.
431431
432432 Args:
433433 drive_name: name of drive where file exists
434434 path: path where original content exists
435435 to_path: path where object should be copied
436+ to_drive: name of drive where to copy object
436437 """
437438 data = {}
438439 try :
439440 # eliminate leading and trailing backslashes
440441 path = path .strip ('/' )
441442
442- await obs .copy_async (self ._content_managers [drive_name ]["store" ], path , to_path )
443- metadata = await obs .head_async (self ._content_managers [drive_name ]["store" ], to_path )
443+ # copy object within same drive
444+ if to_drive == drive_name :
445+ await obs .copy_async (self ._content_managers [drive_name ]["store" ], path , to_path )
446+ metadata = await obs .head_async (self ._content_managers [drive_name ]["store" ], to_path )
447+ # copy object to another drive
448+ else :
449+ content = b''
450+ try :
451+ # retrieving contents of file
452+ file = await obs .get_async (self ._content_managers [drive_name ]["store" ], path )
453+ stream = file .stream (min_chunk_size = 5 * 1024 * 1024 ) # 5MB sized chunks
454+ async for buf in stream :
455+ content += buf
456+ except :
457+ # dealing with a directory, no contents to retrieve
458+ pass
459+
460+ await obs .put_async (self ._content_managers [to_drive ]["store" ], to_path , content )
461+ metadata = await obs .head_async (self ._content_managers [to_drive ]["store" ], to_path )
444462
445463 data = {
446464 "path" : to_path ,
0 commit comments