Skip to main content

IsoEnvironment

Trait IsoEnvironment 

Source
pub trait IsoEnvironment: Send + Sync {
    // Required methods
    fn list_dir(&self, path: &Path) -> Result<Vec<PathBuf>>;
    fn exists(&self, path: &Path) -> bool;
    fn metadata(&self, path: &Path) -> Result<Metadata>;
    fn mount_iso(&self, iso_path: &Path) -> Result<PathBuf, IsoError>;
    fn unmount(&self, mount_point: &Path) -> Result<(), IsoError>;

    // Provided method
    fn validate_path(
        &self,
        base: &Path,
        path: &Path,
    ) -> Result<PathBuf, IsoError> { ... }
}
Expand description

Environment abstraction for file system and OS operations

This trait enables unit testing without actual mounts by providing a mockable interface for filesystem access and process execution.

Required Methods§

Source

fn list_dir(&self, path: &Path) -> Result<Vec<PathBuf>>

List files in a directory.

§Errors

Returns std::io::Error on any read failure (missing path, permission denied, I/O error mid-read).

Source

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

Check if a file exists.

Source

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

Read file metadata.

§Errors

Returns std::io::Error when the path can’t be stat’d (missing, permission denied, I/O error).

Source

fn mount_iso(&self, iso_path: &Path) -> Result<PathBuf, IsoError>

Mount an ISO file and return the mount point.

§Errors

Returns IsoError::MountFailed if the underlying mount command (or mock handler) returned non-zero, or IsoError::Io if a required helper (mkdir, losetup, mount) couldn’t be spawned.

Source

fn unmount(&self, mount_point: &Path) -> Result<(), IsoError>

Unmount a previously mounted ISO.

§Errors

Returns IsoError::MountFailed if umount returned non-zero (busy mount, stale mount point), or IsoError::Io if the unmount helper couldn’t be spawned.

Provided Methods§

Source

fn validate_path(&self, base: &Path, path: &Path) -> Result<PathBuf, IsoError>

Validate that path is rooted under base and contains no parent-directory escapes.

Returns IsoError::PathTraversal when:

  • any path component is .. (could escape on normalization), OR
  • path does not lie under base (absolute paths to elsewhere).

Symlinks are NOT resolved — callers that mount untrusted media must constrain symlink-following at the mount layer (e.g. nosymfollow), not rely on this check.

Previous implementation silently returned Ok(path) when strip_prefix(base) failed, meaning paths outside base were accepted. Fixed in #56.

§Errors

Returns IsoError::PathTraversal on either of the two traversal conditions above.

Implementors§