pub struct ReadWriteFs { /* private fields */ }Expand description
A passthrough filesystem backed by std::fs.
With no root restriction, all operations delegate directly to the real filesystem. When a root is set, paths are confined to the subtree under that root — acting like a lightweight chroot.
§Example
ⓘ
use rust_bash::{RustBashBuilder, ReadWriteFs};
use std::sync::Arc;
let rwfs = ReadWriteFs::with_root("/tmp/sandbox").unwrap();
let mut shell = RustBashBuilder::new()
.fs(Arc::new(rwfs))
.cwd("/")
.build()
.unwrap();
shell.exec("echo hello > /output.txt").unwrap(); // writes to /tmp/sandbox/output.txtImplementations§
Source§impl ReadWriteFs
impl ReadWriteFs
Sourcepub fn with_root(root: impl Into<PathBuf>) -> Result<Self>
pub fn with_root(root: impl Into<PathBuf>) -> Result<Self>
Create a ReadWriteFs restricted to paths under root.
All paths are resolved relative to root. Path traversal beyond
root (via .. or symlinks) is rejected with PermissionDenied.
The root directory must exist and is canonicalized on construction.
Trait Implementations§
Source§impl Default for ReadWriteFs
impl Default for ReadWriteFs
Source§impl VirtualFs for ReadWriteFs
impl VirtualFs for ReadWriteFs
fn read_file(&self, path: &Path) -> Result<Vec<u8>, VfsError>
fn write_file(&self, path: &Path, content: &[u8]) -> Result<(), VfsError>
fn append_file(&self, path: &Path, content: &[u8]) -> Result<(), VfsError>
fn remove_file(&self, path: &Path) -> Result<(), VfsError>
fn mkdir(&self, path: &Path) -> Result<(), VfsError>
fn mkdir_p(&self, path: &Path) -> Result<(), VfsError>
fn readdir(&self, path: &Path) -> Result<Vec<DirEntry>, VfsError>
fn remove_dir(&self, path: &Path) -> Result<(), VfsError>
fn remove_dir_all(&self, path: &Path) -> Result<(), VfsError>
fn exists(&self, path: &Path) -> bool
fn stat(&self, path: &Path) -> Result<Metadata, VfsError>
fn lstat(&self, path: &Path) -> Result<Metadata, VfsError>
fn chmod(&self, path: &Path, mode: u32) -> Result<(), VfsError>
fn utimes(&self, path: &Path, mtime: SystemTime) -> Result<(), VfsError>
fn symlink(&self, target: &Path, link: &Path) -> Result<(), VfsError>
fn hardlink(&self, src: &Path, dst: &Path) -> Result<(), VfsError>
fn readlink(&self, path: &Path) -> Result<PathBuf, VfsError>
fn canonicalize(&self, path: &Path) -> Result<PathBuf, VfsError>
fn copy(&self, src: &Path, dst: &Path) -> Result<(), VfsError>
fn rename(&self, src: &Path, dst: &Path) -> Result<(), VfsError>
fn glob(&self, pattern: &str, cwd: &Path) -> Result<Vec<PathBuf>, VfsError>
Auto Trait Implementations§
impl Freeze for ReadWriteFs
impl RefUnwindSafe for ReadWriteFs
impl Send for ReadWriteFs
impl Sync for ReadWriteFs
impl Unpin for ReadWriteFs
impl UnsafeUnpin for ReadWriteFs
impl UnwindSafe for ReadWriteFs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more