Skip to main content

ReadWriteFs

Struct ReadWriteFs 

Source
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.txt

Implementations§

Source§

impl ReadWriteFs

Source

pub fn new() -> Self

Create a ReadWriteFs with unrestricted access to the real filesystem.

Source

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl VirtualFs for ReadWriteFs

Source§

fn read_file(&self, path: &Path) -> Result<Vec<u8>, VfsError>

Source§

fn write_file(&self, path: &Path, content: &[u8]) -> Result<(), VfsError>

Source§

fn append_file(&self, path: &Path, content: &[u8]) -> Result<(), VfsError>

Source§

fn remove_file(&self, path: &Path) -> Result<(), VfsError>

Source§

fn mkdir(&self, path: &Path) -> Result<(), VfsError>

Source§

fn mkdir_p(&self, path: &Path) -> Result<(), VfsError>

Source§

fn readdir(&self, path: &Path) -> Result<Vec<DirEntry>, VfsError>

Source§

fn remove_dir(&self, path: &Path) -> Result<(), VfsError>

Source§

fn remove_dir_all(&self, path: &Path) -> Result<(), VfsError>

Source§

fn exists(&self, path: &Path) -> bool

Source§

fn stat(&self, path: &Path) -> Result<Metadata, VfsError>

Source§

fn lstat(&self, path: &Path) -> Result<Metadata, VfsError>

Source§

fn chmod(&self, path: &Path, mode: u32) -> Result<(), VfsError>

Source§

fn utimes(&self, path: &Path, mtime: SystemTime) -> Result<(), VfsError>

Source§

fn canonicalize(&self, path: &Path) -> Result<PathBuf, VfsError>

Source§

fn copy(&self, src: &Path, dst: &Path) -> Result<(), VfsError>

Source§

fn rename(&self, src: &Path, dst: &Path) -> Result<(), VfsError>

Source§

fn glob(&self, pattern: &str, cwd: &Path) -> Result<Vec<PathBuf>, VfsError>

Source§

fn deep_clone(&self) -> Arc<dyn VirtualFs>

Create an independent deep copy for subshell isolation. Read more
Source§

fn glob_with_opts( &self, pattern: &str, cwd: &Path, _opts: &GlobOptions, ) -> Result<Vec<PathBuf>, VfsError>

Glob expansion with shopt-controlled options (dotglob, nocaseglob, globstar). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more