Skip to content

Commit ab1af91

Browse files
committed
refactor rename functionality
1 parent 1d3d264 commit ab1af91

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

jupyter_drives/manager.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,19 @@ async def rename_file(self, drive_name, path, new_path):
421421
# eliminate leading and trailing backslashes
422422
path = path.strip('/')
423423

424-
await obs.rename_async(self._content_managers[drive_name]["store"], path, new_path)
425-
metadata = await obs.head_async(self._content_managers[drive_name]["store"], new_path)
424+
object_name = drive_name + '/' + path
425+
new_object_name = drive_name + '/' + new_path
426+
is_dir = await self._check_object(drive_name, path)
427+
if is_dir == True:
428+
object_name = object_name + self._fixDir_suffix
429+
new_object_name = new_object_name + self._fixDir_suffix
430+
431+
await self._file_system._mv_file(object_name, new_object_name)
432+
metadata = await self._file_system._info(new_object_name)
426433

427434
data = {
428435
"path": new_path,
429-
"last_modified": metadata["last_modified"].isoformat(),
436+
"last_modified": metadata["LastModified"].isoformat(),
430437
"size": metadata["size"]
431438
}
432439
except Exception as e:
@@ -580,11 +587,11 @@ async def _get_drive_location(self, drive_name):
580587
return location
581588

582589
async def _check_object(self, drive_name, path):
583-
"""Helping function to check if we are dealing with an empty file or directory.
590+
"""Helping function to check if we are dealing with a file or directory.
584591
585592
Args:
586593
drive_name: name of drive where object exists
587-
path: path to object to check
594+
path: path of object to check
588595
"""
589596
isDir = False
590597
try:

0 commit comments

Comments
 (0)