gui/backend/gui_plugin/core/Files.py
def resolve_path(path, web_session):
    "This function returns a tuple (full path, relative path) with the resolved paths"
    if PurePath(Path(path).name.split(",")[0]).is_reserved():
        raise MSGException(Error.CORE_RESERVED_NOT_ALLOWED,
                           "Reserved paths are not allowed.")

    if not web_session or web_session.is_local_session:
        # This is a local connection
        if os.path.isabs(path):
            return Path(os.path.abspath(path)).as_posix(), Path(os.path.abspath(path)).as_posix()
        return Path(os.path.abspath(os.path.join(str(Path.home()), path))).as_posix(), Path(str(Path.home())).as_posix()

    # This is a remote (non-local) connection
    if os.path.isabs(path):
        raise MSGException(Error.CORE_ABSPATH_NOT_ALLOWED,
                           "Absolute paths are not allowed.")

    user_space = os.path.abspath(mysqlsh.plugin_manager.general.get_shell_user_dir(
        'plugin_data', 'gui_plugin', f"user_{web_session.user_id}"))
    full_path = os.path.abspath(os.path.join(user_space, path))

    if not full_path.startswith(user_space):
        raise MSGException(Error.CORE_ACCESS_OUTSIDE_USERSPACE,
                           "Trying to access outside the user directory.")

    # +1 to remove the leading / since it's a relative path
    return Path(full_path).as_posix(), Path(full_path[len(user_space) + 1:]).as_posix()
This function returns a tuple (full path, relative path) with the resolved paths
This function returns a tuple (full path, relative path) with the resolved paths
This function returns a tuple ( full path relative path ) with the resolved paths
def resolve_path(path, web_session):
    if PurePath(Path(path).name.split(",")[0]).is_reserved():
        raise MSGException(Error.CORE_RESERVED_NOT_ALLOWED,
                           "Reserved paths are not allowed.")
    if not web_session or web_session.is_local_session:
        if os.path.isabs(path):
            return Path(os.path.abspath(path)).as_posix(), Path(os.path.abspath(path)).as_posix()
        return Path(os.path.abspath(os.path.join(str(Path.home()), path))).as_posix(), Path(str(Path.home())).as_posix()
    if os.path.isabs(path):
        raise MSGException(Error.CORE_ABSPATH_NOT_ALLOWED,
                           "Absolute paths are not allowed.")
    user_space = os.path.abspath(mysqlsh.plugin_manager.general.get_shell_user_dir(
        'plugin_data', 'gui_plugin', f"user_{web_session.user_id}"))
    full_path = os.path.abspath(os.path.join(user_space, path))
    if not full_path.startswith(user_space):
        raise MSGException(Error.CORE_ACCESS_OUTSIDE_USERSPACE,
                           "Trying to access outside the user directory.")
    return Path(full_path).as_posix(), Path(full_path[len(user_space) + 1:]).as_posix()
def resolve_path ( path , web_session ) : if PurePath ( Path ( path ) . name . split ( "," ) [ 0 ] ) . is_reserved ( ) : raise MSGException ( Error . CORE_RESERVED_NOT_ALLOWED , "Reserved paths are not allowed." ) if not web_session or web_session . is_local_session : if os . path . isabs ( path ) : return Path ( os . path . abspath ( path ) ) . as_posix ( ) , Path ( os . path . abspath ( path ) ) . as_posix ( ) return Path ( os . path . abspath ( os . path . join ( str ( Path . home ( ) ) , path ) ) ) . as_posix ( ) , Path ( str ( Path . home ( ) ) ) . as_posix ( ) if os . path . isabs ( path ) : raise MSGException ( Error . CORE_ABSPATH_NOT_ALLOWED , "Absolute paths are not allowed." ) user_space = os . path . abspath ( mysqlsh . plugin_manager . general . get_shell_user_dir ( 'plugin_data' , 'gui_plugin' , f"user_{web_session.user_id}" ) ) full_path = os . path . abspath ( os . path . join ( user_space , path ) ) if not full_path . startswith ( user_space ) : raise MSGException ( Error . CORE_ACCESS_OUTSIDE_USERSPACE , "Trying to access outside the user directory." ) return Path ( full_path ) . as_posix ( ) , Path ( full_path [ len ( user_space ) + 1 : ] ) . as_posix ( )
This function returns a tuple (full path, relative path) with the resolved paths
This function returns a tuple ( full path relative path ) with the resolved paths
"This function returns a tuple (full path, relative path) with the resolved paths" # This is a local connection # This is a remote (non-local) connection # +1 to remove the leading / since it's a relative path
path
web_session