@@ -427,6 +427,7 @@ async def rename_file(self, drive_name, path, new_path):
427427 if is_dir == True :
428428 object_name = object_name + self ._fixDir_suffix
429429 new_object_name = new_object_name + self ._fixDir_suffix
430+ await self ._fix_dir (drive_name , path )
430431
431432 await self ._file_system ._mv_file (object_name , new_object_name )
432433 metadata = await self ._file_system ._info (new_object_name )
@@ -599,13 +600,38 @@ async def _check_object(self, drive_name, path):
599600 if response ["type" ]== 'directory' :
600601 isDir = True
601602 except Exception as e :
602- raise tornado .web .HTTPError (
603+ raise tornado .web .HTTPError (
603604 status_code = httpx .codes .BAD_REQUEST ,
604605 reason = f"The following error occured when checking the object information: { e } " ,
605606 )
606607
607608 return isDir
608609
610+ async def _fix_dir (self , drive_name , path ):
611+ """Helping function to fix a directory. It applies to the S3 folders created in the AWS console.
612+
613+ Args:
614+ drive_name: name of drive where object exists
615+ path: path of object to fix
616+ """
617+ try :
618+ check = await self ._file_system ._exists (drive_name + '/' + path + self ._fixDir_suffix )
619+ if check == True : # directory has right format
620+ return
621+ else : # directory was created from console
622+ # delete original object
623+ 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 :
624+ await client .delete_object (Bucket = drive_name , Key = path + '/' )
625+ # create new directory
626+ await self ._file_system ._touch (drive_name + '/' + path + self ._fixDir_suffix )
627+ except Exception as e :
628+ raise tornado .web .HTTPError (
629+ status_code = httpx .codes .BAD_REQUEST ,
630+ reason = f"The following error occured when fixing the directory object: { e } " ,
631+ )
632+
633+ return
634+
609635 async def _call_provider (
610636 self ,
611637 url : str ,
0 commit comments