Skip to main content

OverlayFs

Struct OverlayFs 

Source
pub struct OverlayFs { /* private fields */ }
Expand description

A copy-on-write filesystem: reads from a real directory, writes to memory.

The lower layer (a real directory on disk) is treated as read-only. All mutations go to the upper InMemoryFs layer. Deletions are tracked via a whiteout set so deleted lower-layer entries appear as removed.

§Example

use rust_bash::{RustBashBuilder, OverlayFs};
use std::sync::Arc;

let overlay = OverlayFs::new("./my_project").unwrap();
let mut shell = RustBashBuilder::new()
    .fs(Arc::new(overlay))
    .cwd("/")
    .build()
    .unwrap();

let result = shell.exec("cat /src/main.rs").unwrap(); // reads from disk
shell.exec("echo new > /src/main.rs").unwrap();       // writes to memory only

Implementations§

Source§

impl OverlayFs

Source

pub fn new(lower: impl Into<PathBuf>) -> Result<Self>

Create an overlay filesystem with lower as the read-only base.

The lower directory must exist and be a directory. It is canonicalized on construction so symlinks in the lower path itself are resolved once.

Trait Implementations§

Source§

impl VirtualFs for OverlayFs

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