Skip to content

Commit

Permalink
update delete drive functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisaCG committed Jan 13, 2025
1 parent 34be2a4 commit b1c2577
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions jupyter_drives/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,17 +445,22 @@ async def delete_file(self, drive_name, path):
try:
# eliminate leading and trailing backslashes
path = path.strip('/')
is_dir = await self._file_system._isdir(drive_name + '/' + path)
if is_dir == True:
await self._fix_dir(drive_name, path)
await self._file_system._rm(drive_name + '/' + path, recursive = True)
object_name = drive_name # in case we are only deleting the drive itself
if path != '':
# deleting objects within a drive
is_dir = await self._file_system._isdir(drive_name + '/' + path)
if is_dir == True:
await self._fix_dir(drive_name, path)
object_name = drive_name + '/' + path
await self._file_system._rm(object_name, recursive = True)

# checking for remaining directories and deleting them
stream = obs.list(self._content_managers[drive_name]["store"], path, chunk_size=100, return_arrow=True)
async for batch in stream:
contents_list = pyarrow.record_batch(batch).to_pylist()
for object in contents_list:
await self._fix_dir(drive_name, object["path"], delete_only = True)
if object_name != drive_name:
stream = obs.list(self._content_managers[drive_name]["store"], path, chunk_size=100, return_arrow=True)
async for batch in stream:
contents_list = pyarrow.record_batch(batch).to_pylist()
for object in contents_list:
await self._fix_dir(drive_name, object["path"], delete_only = True)

except Exception as e:
raise tornado.web.HTTPError(
Expand Down

0 comments on commit b1c2577

Please sign in to comment.