@@ -458,7 +458,17 @@ async def delete_file(self, drive_name, path):
458458 try :
459459 # eliminate leading and trailing backslashes
460460 path = path .strip ('/' )
461- await obs .delete_async (self ._content_managers [drive_name ]["store" ], path )
461+ is_dir = await self ._file_system ._isdir (drive_name + '/' + path )
462+ if is_dir == True :
463+ await self ._fix_dir (drive_name , path )
464+ await self ._file_system ._rm (drive_name + '/' + path , recursive = True )
465+
466+ # checking for remaining directories and deleting them
467+ stream = obs .list (self ._content_managers [drive_name ]["store" ], path , chunk_size = 100 , return_arrow = True )
468+ async for batch in stream :
469+ contents_list = pyarrow .record_batch (batch ).to_pylist ()
470+ for object in contents_list :
471+ await self ._fix_dir (drive_name , object ["path" ], delete_only = True )
462472
463473 except Exception as e :
464474 raise tornado .web .HTTPError (
@@ -607,7 +617,7 @@ async def _check_object(self, drive_name, path):
607617
608618 return isDir
609619
610- async def _fix_dir (self , drive_name , path ):
620+ async def _fix_dir (self , drive_name , path , delete_only = False ):
611621 """Helping function to fix a directory. It applies to the S3 folders created in the AWS console.
612622
613623 Args:
@@ -622,6 +632,8 @@ async def _fix_dir(self, drive_name, path):
622632 # delete original object
623633 async with self ._s3_session .create_client ('s3' , aws_secret_access_key = self ._config .secret_access_key , aws_access_key_id = self ._config .access_key_id , aws_session_token = self ._config .session_token ) as client :
624634 await client .delete_object (Bucket = drive_name , Key = path + '/' )
635+ if delete_only == True :
636+ return
625637 # create new directory
626638 await self ._file_system ._touch (drive_name + '/' + path + self ._fixDir_suffix )
627639 except Exception as e :
0 commit comments