Skip to content

Commit 0084da7

Browse files
committed
refactor copy functionality
1 parent e36eccd commit 0084da7

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

jupyter_drives/manager.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -511,29 +511,26 @@ async def copy_file(self, drive_name, path, to_path, to_drive):
511511
# eliminate leading and trailing backslashes
512512
path = path.strip('/')
513513

514-
# copy object within same drive
514+
object_name = drive_name + '/' + path
515+
# copy objects within same drive
515516
if to_drive == drive_name:
516-
await obs.copy_async(self._content_managers[drive_name]["store"], path, to_path)
517-
metadata = await obs.head_async(self._content_managers[drive_name]["store"], to_path)
518-
# copy object to another drive
517+
to_object_name = drive_name + '/' + to_path
518+
# copy objects to another drive
519519
else:
520-
content = b''
521-
try:
522-
# retrieving contents of file
523-
file = await obs.get_async(self._content_managers[drive_name]["store"], path)
524-
stream = file.stream(min_chunk_size=5 * 1024 * 1024) # 5MB sized chunks
525-
async for buf in stream:
526-
content += buf
527-
except:
528-
# dealing with a directory, no contents to retrieve
529-
pass
530-
531-
await obs.put_async(self._content_managers[to_drive]["store"], to_path, content)
532-
metadata = await obs.head_async(self._content_managers[to_drive]["store"], to_path)
520+
to_object_name = to_drive + '/' + to_path
521+
522+
is_dir = await self._check_object(drive_name, path)
523+
if is_dir == True:
524+
object_name = object_name + self._fixDir_suffix
525+
to_object_name = to_object_name + self._fixDir_suffix
526+
await self._fix_dir(drive_name, path)
527+
528+
await self._file_system._copy(object_name, to_object_name)
529+
metadata = await self._file_system._info(to_object_name)
533530

534531
data = {
535532
"path": to_path,
536-
"last_modified": metadata["last_modified"].isoformat(),
533+
"last_modified": metadata["LastModified"].isoformat(),
537534
"size": metadata["size"]
538535
}
539536
except Exception as e:

0 commit comments

Comments
 (0)