gravitino.filesystem.gvfs_hook.GravitinoVirtualFileSystemHook¶
- class gravitino.filesystem.gvfs_hook.GravitinoVirtualFileSystemHook¶
Bases:
ABC
Represents a hook that can be used to intercept file system operations. The implementor should handle the exception, if any, in the pre-hook method, otherwise the exception will be thrown to the caller and fail the operation. Besides, the implemented pre-hook method should be lightweight and fast, otherwise it will slow down the operation. The pre-hook method may be called more than once and in parallel, so the implementor should handle the concurrent and idempotent issues if required.
- __init__()¶
Methods
__init__
()initialize
(config)Initialize the hook with the configuration.
post_cat_file
(gvfs_path, start, end, ...)Called after a file is read.
post_cp_file
(src_gvfs_path, dst_gvfs_path, ...)Called after a file is copied.
post_created
(gvfs_path, created)Called after the creation time of a file is retrieved.
post_exists
(gvfs_path, exists, **kwargs)Called after the existence of a file or a directory is checked.
post_get_file
(gvfs_path, local_path, ...)Called after a file is downloaded.
post_info
(info, **kwargs)Called after the information of a file is retrieved.
post_ls
(detail, entries, **kwargs)Called after a directory is listed.
post_makedirs
(gvfs_path, exist_ok)Called after a directory is created.
post_mkdir
(gvfs_path, create_parents, **kwargs)Called after a directory is created.
post_modified
(gvfs_path, modified)Called after the modification time of a file is retrieved.
post_mv
(src_gvfs_path, dst_gvfs_path, ...)Called after a file or a directory is moved.
post_open
(gvfs_path, mode, block_size, ...)Called after a file is opened.
post_rm
(gvfs_path, recursive, maxdepth)Called after a file or a directory is removed.
post_rm_file
(gvfs_path)Called after a file is removed.
post_rmdir
(gvfs_path)Called after a directory is removed.
pre_cat_file
(path, start, end, **kwargs)Called before a file is read.
pre_cp_file
(src, dst, **kwargs)Called before a file is copied.
pre_created
(path)Called before the creation time of a file is retrieved.
pre_exists
(path, **kwargs)Called before the existence of a file or a directory is checked.
pre_get_file
(rpath, lpath, callback, ...)Called before a file is downloaded.
pre_info
(path, **kwargs)Called before the information of a file is retrieved.
pre_ls
(path, detail, **kwargs)Called before a directory is listed.
pre_makedirs
(path, exist_ok)Called before a directory is created.
pre_mkdir
(path, create_parents, **kwargs)Called before a directory is created.
pre_modified
(path)Called before the modification time of a file is retrieved.
pre_mv
(src, dst, recursive, maxdepth, **kwargs)Called before a file or a directory is moved.
pre_open
(path, mode, block_size, ...)Called before a file is opened.
pre_rm
(path, recursive, maxdepth)Called before a file or a directory is removed.
pre_rm_file
(path)Called before a file is removed.
pre_rmdir
(path)Called before a directory is removed.
- abstract initialize(config: Dict[str, str] | None)¶
Initialize the hook with the configuration. This method will be called in the GVFS initialize method, and the configuration will be passed from the GVFS configuration. The implementor can initialize the hook with the configuration. The exception will be thrown to the caller and fail the GVFS initialization.
- Args:
config: The configuration.
- abstract post_cat_file(gvfs_path: str, start: int, end: int, content: Any, **kwargs) Any ¶
Called after a file is read. The implementor can modify the content for customization. The exception will be thrown to the caller and fail the cat_file operation.
- Args:
gvfs_path: The GVFS path of the file. start: The start position to read. end: The end position to read. content: The content of the file. **kwargs: Additional arguments.
- Returns:
The content to cat_file.
- abstract post_cp_file(src_gvfs_path: str, dst_gvfs_path: str, **kwargs)¶
Called after a file is copied. if this method is invoked, it means that the cp_file is succeeded. The exception in the method will be thrown to the caller and fail the operation.
- Args:
src_gvfs_path: The source GVFS path. dst_gvfs_path: The destination GVFS path. **kwargs: Additional arguments
- abstract post_created(gvfs_path: str, created: Any) Any ¶
Called after the creation time of a file is retrieved. The implementor can modify the created time for customization. The exception will be thrown to the caller and fail the created operation.
- Args:
gvfs_path: The GVFS path of the file. created: The creation time of the file.
- Returns:
The creation time to get.
- abstract post_exists(gvfs_path: str, exists: bool, **kwargs) bool ¶
Called after the existence of a file or a directory is checked. The implementor can modify the value for customization. The exception will be thrown to the caller and fail the exists operation.
- Args:
gvfs_path: The GVFS path of the file or the directory exists: The existence of the file or the directory. **kwargs: Additional arguments.
- Returns:
The existence to check.
- post_get_file(gvfs_path: str, local_path: str, outfile: str, **kwargs)¶
Called after a file is downloaded. If this method is invoked, it means that the get_file is succeeded. The exception will be thrown to the caller and fail the get_file operation.
- Args:
gvfs_path: The GVFS path of the file. local_path: The local path of the file. outfile: The output file. **kwargs: Additional arguments
- abstract post_info(info: Dict[str, Any], **kwargs) Dict[str, Any] ¶
Called after the information of a file is retrieved. The implementor can modify the info for customization. The exception will be thrown to the caller and fail the info operation.
- Args:
info: The information of the file. **kwargs: Additional arguments.
- Returns:
The information to get.
- abstract post_ls(detail: bool, entries: List[str | Dict[str, Any]], **kwargs) List[str | Dict[str, Any]] ¶
Called after a directory is listed. The implementor can modify the entries for customization. The exception will be thrown to the caller and fail the ls operation.
- Args:
detail: Whether to list the directory in detail. entries: The entries of the directory. It can be a list of str if the detail is False,
or a list of dict if the detail is True.
**kwargs: Additional arguments.
- Returns:
The entries to list.
- post_makedirs(gvfs_path: str, exist_ok: bool)¶
Called after a directory is created. If this method is invoked, it means that the makedirs is succeeded. The exception will be thrown to the caller and fail the makedirs operation.
- Args:
gvfs_path: The GVFS path of the directory. exist_ok: Whether to exist the directory.
- abstract post_mkdir(gvfs_path: str, create_parents: bool, **kwargs)¶
Called after a directory is created. If this method is invoked, it means that the mkdir is succeeded. The exception will be thrown to the caller and fail the mkdir operation.
- Args:
gvfs_path: The GVFS path of the directory. create_parents: Whether to create the parent directories. **kwargs: Additional arguments.
- abstract post_modified(gvfs_path: str, modified: Any) Any ¶
Called after the modification time of a file is retrieved. The implementor can modify the modified time for customization. The exception will be thrown to the caller and fail the modified operation.
- Args:
gvfs_path: The GVFS path of the file. modified: The modification time of the file.
- Returns:
The modification time to get.
- abstract post_mv(src_gvfs_path: str, dst_gvfs_path: str, recursive: bool, maxdepth: int, **kwargs)¶
Called after a file or a directory is moved. If this method is invoked, it means that the mv is succeeded. The exception in the method will be thrown to the caller and fail the operation.
- Args:
src_gvfs_path: The source GVFS path. dst_gvfs_path: The destination GVFS path. recursive: Whether to move the file or directory recursively. maxdepth: The maximum depth to move. **kwargs: Additional arguments
- abstract post_open(gvfs_path: str, mode: str, block_size: int, cache_options: dict, compression: str, file: Any, **kwargs) Any ¶
Called after a file is opened. The implementor can modify the file object for customization. The exception will be thrown to the caller and fail the open operation.
- Args:
gvfs_path: The GVFS path of the file. mode: The mode to open the file. block_size: The block size of the file. cache_options: The cache options of the file. compression: The compression of the file. file: The file object to open. **kwargs: Additional arguments.
- Returns:
The file to open.
- abstract post_rm(gvfs_path: str, recursive: bool, maxdepth: int)¶
Called after a file or a directory is removed. If this method is invoked, it means that the rm is succeeded. The exception will be thrown to the caller and fail the rm operation.
- Args:
gvfs_path: The GVFS path of the file or the directory. recursive: Whether to remove the file or directory recursively. maxdepth: The maximum depth to remove.
- abstract post_rm_file(gvfs_path: str)¶
Called after a file is removed. If this method is invoked, it means that the rm_file is succeeded. The exception will be thrown to the caller and fail the rm_file operation.
- Args:
gvfs_path: The GVFS path of the file.
- post_rmdir(gvfs_path: str)¶
Called after a directory is removed. If this method is invoked, it means that the rmdir is succeeded. The exception will be thrown to the caller and fail the rmdir operation.
- Args:
gvfs_path: The GVFS path of the directory.
- abstract pre_cat_file(path: str, start: int, end: int, **kwargs) str ¶
Called before a file is read. The returned path will be used for the cat_file operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the cat_file operation.
- Args:
path: The path of the file. start: The start position to read. end: The end position to read. **kwargs: Additional arguments.
- Returns:
The path to cat_file.
- abstract pre_cp_file(src: str, dst: str, **kwargs) Tuple[str, str] ¶
Called before a file is copied. The returned source and destination will be used for the cp operation. The implementor can modify the source and destination for customization. The exception will be thrown to the caller and fail the cp operation.
- Args:
src: The source file. dst: The destination file. **kwargs: Additional arguments.
- Returns:
The source and destination to copy.
- abstract pre_created(path: str) str ¶
Called before the creation time of a file is retrieved. The returned path will be used for the created operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the created operation.
- Args:
path: The path of the file.
- Returns:
The path to get the creation time.
- abstract pre_exists(path: str, **kwargs) str ¶
Called before the existence of a file or a directory is checked. The returned path will be used for the exists operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the exists operation.
- Args:
path: The path of the file or the directory. **kwargs: Additional arguments.
- Returns:
The path to check the existence.
- abstract pre_get_file(rpath: str, lpath: str, callback: Callback, outfile: str, **kwargs) str ¶
Called before a file is downloaded. The returned path will be used for the get_file operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the get_file operation.
- Args:
rpath: The remote path of the file. lpath: The local path of the file. callback: The callback to call. outfile: The output file. **kwargs: Additional arguments.
- Returns:
The path to get_file.
- abstract pre_info(path: str, **kwargs) str ¶
Called before the information of a file is retrieved. The returned path will be used for the info operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the info operation.
- Args:
path: The path of the file. **kwargs: Additional arguments.
- Returns:
The path to get the information.
- abstract pre_ls(path: str, detail: bool, **kwargs) str ¶
Called before a directory is listed. The returned path will be used for the ls operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the ls operation.
- Args:
path: The path of the directory. detail: Whether to list the directory in detail. **kwargs: Additional arguments.
- Returns:
The path to list.
- abstract pre_makedirs(path: str, exist_ok: bool) str ¶
Called before a directory is created. The returned path will be used for the makedirs operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the makedirs operation.
- Args:
path: The path of the directory. exist_ok: Whether to exist the directory.
- Returns:
The path to makedirs.
- abstract pre_mkdir(path: str, create_parents: bool, **kwargs) str ¶
Called before a directory is created. The returned path will be used for the mkdir operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the mkdir operation.
- Args:
path: The path of the directory. create_parents: Whether to create the parent directories. **kwargs: Additional arguments.
- Returns:
The path to mkdir.
- abstract pre_modified(path: str) str ¶
Called before the modification time of a file is retrieved. The returned path will be used for the modified operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the modified operation.
- Args:
path: The path of the file.
- Returns:
The path to get the modification time.
- abstract pre_mv(src: str, dst: str, recursive: bool, maxdepth: int, **kwargs) Tuple[str, str] ¶
Called before a file or a directory is moved. The returned source and destination will be used for the mv operation. The implementor can modify the source and destination for customization. The exception will be thrown to the caller and fail the mv operation.
- Args:
src: The source file or directory. dst: The destination file or directory. recursive: Whether to move the file or directory recursively. maxdepth: The maximum depth to move. **kwargs: Additional arguments.
- Returns:
The source and destination to move.
- abstract pre_open(path: str, mode: str, block_size: int, cache_options: dict, compression: str, **kwargs) str ¶
Called before a file is opened. The returned path will be used for the open operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the open operation.
- Args:
path: The path of the file. mode: The mode to open the file. block_size: The block size of the file. cache_options: The cache options of the file. compression: The compression of the file. **kwargs: Additional arguments.
- Returns:
The path to open.
- abstract pre_rm(path: str, recursive: bool, maxdepth: int) str ¶
Called before a file or a directory is removed. The returned path will be used for the rm operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the rm operation.
- Args:
path: The path of the file or the directory. recursive: Whether to remove the file or directory recursively. maxdepth: The maximum depth to remove.
- Returns:
The path to remove.
- abstract pre_rm_file(path: str) str ¶
Called before a file is removed. The returned path will be used for the rm_file operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the rm_file operation.
- Args:
path: The path of the file.
- Returns:
The path to remove.
- abstract pre_rmdir(path: str) str ¶
Called before a directory is removed. The returned path will be used for the rmdir operation. The implementor can modify the path for customization. The exception will be thrown to the caller and fail the rmdir operation.
- Args:
path: The path of the directory.
- Returns:
The path to remove.