2525
2626import re
2727
28+ # constant used as suffix to deal with directory objects
29+ EMPTY_DIR_SUFFIX = '/.jupyter_drives_fix_dir'
30+
2831class JupyterDrivesManager ():
2932 """
3033 Jupyter-drives manager class.
@@ -49,8 +52,7 @@ def __init__(self, config: traitlets.config.Config) -> None:
4952
5053 # initiate aiobotocore session if we are dealing with S3 drives
5154 if self ._config .provider == 's3' :
52- if self ._config .access_key_id and self ._config .secret_access_key :
53- self ._fixDir_suffix = '/.jupyter-drives-fixDir' # fix for creating directories
55+ if self ._config .access_key_id and self ._config .secret_access_key :
5456 self ._s3_clients = {}
5557 self ._s3_session = get_session ()
5658 self ._file_system = s3fs .S3FileSystem (anon = False , asynchronous = True , key = self ._config .access_key_id , secret = self ._config .secret_access_key , token = self ._config .session_token )
@@ -311,7 +313,7 @@ async def new_file(self, drive_name, path, type):
311313 object_name = drive_name + '/' + path
312314 # in the case of S3 directories, we need to add a suffix to feign the creation of a directory
313315 if type == 'directory' and self ._config .provider == 's3' :
314- object_name = object_name + self . _fixDir_suffix
316+ object_name = object_name + EMPTY_DIR_SUFFIX
315317
316318 await self ._file_system ._touch (object_name )
317319 metadata = await self ._file_system ._info (object_name )
@@ -409,8 +411,8 @@ async def rename_file(self, drive_name, path, new_path):
409411 new_object_name = drive_name + '/' + new_path
410412 is_dir = await self ._file_system ._isdir (object_name )
411413 if is_dir == True :
412- object_name = object_name + self . _fixDir_suffix
413- new_object_name = new_object_name + self . _fixDir_suffix
414+ object_name = object_name + EMPTY_DIR_SUFFIX
415+ new_object_name = new_object_name + EMPTY_DIR_SUFFIX
414416 await self ._fix_dir (drive_name , path )
415417
416418 await self ._file_system ._mv_file (object_name , new_object_name )
@@ -486,8 +488,8 @@ async def copy_file(self, drive_name, path, to_path, to_drive):
486488
487489 is_dir = await self ._file_system ._isdir (object_name )
488490 if is_dir == True :
489- object_name = object_name + self . _fixDir_suffix
490- to_object_name = to_object_name + self . _fixDir_suffix
491+ object_name = object_name + EMPTY_DIR_SUFFIX
492+ to_object_name = to_object_name + EMPTY_DIR_SUFFIX
491493 await self ._fix_dir (drive_name , path )
492494
493495 await self ._file_system ._copy (object_name , to_object_name )
@@ -567,7 +569,7 @@ async def _fix_dir(self, drive_name, path, delete_only = False):
567569 path: path of object to fix
568570 """
569571 try :
570- check = await self ._file_system ._exists (drive_name + '/' + path + self . _fixDir_suffix )
572+ check = await self ._file_system ._exists (drive_name + '/' + path + EMPTY_DIR_SUFFIX )
571573 if check == True : # directory has right format
572574 return
573575 else : # directory was created from console
@@ -577,7 +579,7 @@ async def _fix_dir(self, drive_name, path, delete_only = False):
577579 if delete_only == True :
578580 return
579581 # create new directory
580- await self ._file_system ._touch (drive_name + '/' + path + self . _fixDir_suffix )
582+ await self ._file_system ._touch (drive_name + '/' + path + EMPTY_DIR_SUFFIX )
581583 except Exception as e :
582584 raise tornado .web .HTTPError (
583585 status_code = httpx .codes .BAD_REQUEST ,
0 commit comments