Skip to main content

Fs

Trait Fs 

Source
pub trait Fs: Send + Sync {
Show 18 methods // Required methods fn stat(&self, path: &Path) -> Result<FsMetadata>; fn lstat(&self, path: &Path) -> Result<FsMetadata>; fn open_read(&self, path: &Path) -> Result<Box<dyn Read + Send + Sync>>; fn read_file(&self, path: &Path) -> Result<Vec<u8>>; fn read_to_string(&self, path: &Path) -> Result<String>; fn write_file(&self, path: &Path, contents: &[u8]) -> Result<()>; fn mkdir_all(&self, path: &Path) -> Result<()>; fn symlink(&self, original: &Path, link: &Path) -> Result<()>; fn readlink(&self, path: &Path) -> Result<PathBuf>; fn remove_file(&self, path: &Path) -> Result<()>; fn remove_dir_all(&self, path: &Path) -> Result<()>; fn exists(&self, path: &Path) -> bool; fn is_symlink(&self, path: &Path) -> bool; fn is_dir(&self, path: &Path) -> bool; fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>>; fn rename(&self, from: &Path, to: &Path) -> Result<()>; fn copy_file(&self, from: &Path, to: &Path) -> Result<()>; fn set_permissions(&self, path: &Path, mode: u32) -> Result<()>;
}
Expand description

Filesystem abstraction.

All dodot code accesses the filesystem through this trait so that:

  • Tests can use isolated temp directories with a real implementation
  • Every io::Error is wrapped with the path that caused it

Use &dyn Fs (trait objects) throughout the codebase. The operations are I/O-bound so dynamic dispatch costs nothing meaningful, and generics would infect every type signature.

Required Methods§

Source

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

Returns metadata for the path, following symlinks.

Source

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

Returns metadata for the path without following symlinks.

Source

fn open_read(&self, path: &Path) -> Result<Box<dyn Read + Send + Sync>>

Opens the file for reading in a streaming fashion.

Errors that occur while opening the file are returned through this method’s Result and include path context. Once opened, the returned reader is a raw std::io::Read, so any later read() errors are reported as plain std::io::Error values and are not automatically wrapped with the path.

Source

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

Reads the entire file into bytes.

Source

fn read_to_string(&self, path: &Path) -> Result<String>

Reads the entire file as a UTF-8 string.

Source

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

Writes contents to path, creating or truncating the file.

Source

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

Creates path and all parent directories.

Creates a symbolic link at link pointing to original.

Reads the target of a symbolic link.

Source

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

Removes a file or symlink (not a directory).

Source

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

Removes a directory and all of its contents.

Source

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

Returns true if path exists (follows symlinks).

Returns true if path is a symlink (does not follow).

Source

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

Returns true if path is a directory (follows symlinks).

Source

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

Lists entries in a directory, sorted by name.

Source

fn rename(&self, from: &Path, to: &Path) -> Result<()>

Renames (moves) from to to.

Source

fn copy_file(&self, from: &Path, to: &Path) -> Result<()>

Copies a file from from to to.

Source

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

Sets file permissions (Unix mode).

Implementors§

Source§

impl Fs for OsFs