pub struct Vfs { /* private fields */ }Implementations§
Source§impl Vfs
impl Vfs
pub fn new() -> Self
Sourcepub fn new_host_root(root: impl AsRef<Path>) -> Result<Self>
pub fn new_host_root(root: impl AsRef<Path>) -> Result<Self>
Project tree backed by a host directory (same path as the Lima workspace_parent mount).
§Errors
I/O errors from std::fs::create_dir_all or std::fs::canonicalize.
Sourcepub const fn is_host_backed(&self) -> bool
pub const fn is_host_backed(&self) -> bool
true when this instance uses the host directory (Self::new_host_root) instead of the in-memory tree.
Sourcepub const fn from_parts(root: Node, cwd: String) -> Self
pub const fn from_parts(root: Node, cwd: String) -> Self
Construct VFS from root node and cwd (used by deserialization).
pub fn cwd(&self) -> &str
pub const fn root(&self) -> &Node
Sourcepub fn resolve_absolute(&self, path: &str) -> Result<Node, VfsError>
pub fn resolve_absolute(&self, path: &str) -> Result<Node, VfsError>
Resolve an absolute path to a node. Path must be absolute (normalized). Trailing ‘/’ is trimmed.
§Errors
Returns VfsError::InvalidPath if any segment is missing.
Sourcepub fn resolve_to_absolute(&self, path: &str) -> String
pub fn resolve_to_absolute(&self, path: &str) -> String
将任意路径(相对或绝对)归一化并解析为绝对路径字符串。 相对路径先与 cwd 拼接再归一化,这样 “..” 能正确退到上级目录。
Sourcepub fn mkdir(&mut self, path: &str) -> Result<(), VfsError>
pub fn mkdir(&mut self, path: &str) -> Result<(), VfsError>
Create directory at path (mkdir_all style). Creates any missing parent directories.
§Errors
Returns VfsError::InvalidPath if any path component exists and is not a directory.
Sourcepub fn write_file(&mut self, path: &str, content: &[u8]) -> Result<(), VfsError>
pub fn write_file(&mut self, path: &str, content: &[u8]) -> Result<(), VfsError>
Create or overwrite a file at path. Parent directory must exist and be a directory.
§Errors
Returns VfsError::InvalidPath if parent path does not exist or a component is not a directory.
Sourcepub fn read_file(&self, path: &str) -> Result<Vec<u8>, VfsError>
pub fn read_file(&self, path: &str) -> Result<Vec<u8>, VfsError>
Read file content at path.
§Errors
Returns VfsError::InvalidPath if path does not exist or is not a file.
Sourcepub fn list_dir(&self, path: &str) -> Result<Vec<String>, VfsError>
pub fn list_dir(&self, path: &str) -> Result<Vec<String>, VfsError>
List directory entries at path.
§Errors
Returns VfsError::InvalidPath if path does not exist or is not a directory.
Sourcepub fn set_cwd(&mut self, path: &str) -> Result<(), VfsError>
pub fn set_cwd(&mut self, path: &str) -> Result<(), VfsError>
Set current working directory to path.
§Errors
Returns VfsError::InvalidPath if path does not exist or is not a directory.
Sourcepub fn copy_tree_to_host(
&self,
vfs_path: &str,
host_dir: &Path,
) -> Result<(), VfsError>
pub fn copy_tree_to_host( &self, vfs_path: &str, host_dir: &Path, ) -> Result<(), VfsError>
Recursively copy the VFS subtree at vfs_path to the host directory host_dir.
For each Dir creates a directory; for each File writes file content.
§Errors
Returns VfsError::InvalidPath if path does not exist; VfsError::Io on host I/O failure.