Skip to content

Commit b1c2577

Browse files
committed
update delete drive functionality
1 parent 34be2a4 commit b1c2577

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

jupyter_drives/manager.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,22 @@ async def delete_file(self, drive_name, path):
445445
try:
446446
# eliminate leading and trailing backslashes
447447
path = path.strip('/')
448-
is_dir = await self._file_system._isdir(drive_name + '/' + path)
449-
if is_dir == True:
450-
await self._fix_dir(drive_name, path)
451-
await self._file_system._rm(drive_name + '/' + path, recursive = True)
448+
object_name = drive_name # in case we are only deleting the drive itself
449+
if path != '':
450+
# deleting objects within a drive
451+
is_dir = await self._file_system._isdir(drive_name + '/' + path)
452+
if is_dir == True:
453+
await self._fix_dir(drive_name, path)
454+
object_name = drive_name + '/' + path
455+
await self._file_system._rm(object_name, recursive = True)
452456

453457
# checking for remaining directories and deleting them
454-
stream = obs.list(self._content_managers[drive_name]["store"], path, chunk_size=100, return_arrow=True)
455-
async for batch in stream:
456-
contents_list = pyarrow.record_batch(batch).to_pylist()
457-
for object in contents_list:
458-
await self._fix_dir(drive_name, object["path"], delete_only = True)
458+
if object_name != drive_name:
459+
stream = obs.list(self._content_managers[drive_name]["store"], path, chunk_size=100, return_arrow=True)
460+
async for batch in stream:
461+
contents_list = pyarrow.record_batch(batch).to_pylist()
462+
for object in contents_list:
463+
await self._fix_dir(drive_name, object["path"], delete_only = True)
459464

460465
except Exception as e:
461466
raise tornado.web.HTTPError(

0 commit comments

Comments
 (0)