Crate rivia_vfs

source ·
Expand description

rivia-vfs provides an ergonomic veneer over rivia’s VirtualFileSystem implementation

This ergonomic approach allows for a clean namespaced usage of the VirtualFileSystem implementation e.g. vfs::abs(). Additionally a mechanism is provided to seamlessly switch out the VFS provider dynamically.

§Switching VFS providers

By default the VFS backend provider will be set to Stdfs which is an implementation wrapping the standard library std::fs and related functions to satisfy the VirtualFileSystem trait; however you change the backend provider by simply calling the vfs::set() function and pass in a different variant of the Vfs enum.

§Example

use rivia_vfs::prelude::*;

fn main() {
    // Simply remove this line to default to the real filesystem.
    vfs::set_memfs().unwrap();

    let config = load_config();
    assert_eq!(config, "this is a test");
    println!("VFS test passed");
}

// Load an example application configuration file using VFS.
// This allows you to test with a memory backed VFS implementation during testing and with
// the real filesystem during production.
fn load_config() -> String {
    let dir = PathBuf::from("/etc/xdg");
    vfs::mkdir_p(&dir).unwrap();
    let filepath = dir.mash("rivia.toml");
    vfs::write_all(&filepath, "this is a test").unwrap();
    assert_eq!(vfs::config_dir("rivia.toml").unwrap().to_str().unwrap(), "/etc/xdg");

    if let Some(config_dir) = vfs::config_dir("rivia.toml") {
        let path = config_dir.mash("rivia.toml");
        return vfs::read_all(&path).unwrap();
    }
    "".into()
}

Modules§

Macros§

Structs§

  • VFS is a virtual filesystem singleton providing an implementation of Vfs that defaults to Stdfs but can be changed dynamically to any variant of the Vfs enum.

Functions§

  • Return the path in an absolute clean form
  • Returns all dirs for the given path recursively
  • Returns all files for the given path recursively
  • Returns all paths for the given path recursively
  • Opens a file in append mode
  • Append the given data to to the target file
  • Append the given line to to the target file including a newline
  • Append the given lines to to the target file including newlines
  • Change all file/dir permissions recursivly to mode
  • Returns a new Chmod builder for advanced chmod options
  • Change the ownership of the path recursivly
  • Creates new Chown for use with the builder pattern
  • Returns the highest priority active configuration directory.
  • Copies src to dst recursively
  • Creates a new Copier for use with the builder pattern
  • Returns the current working directory
  • Returns all directories for the given path, sorted by name
  • Returns an iterator over the given path
  • Return a virtual filesystem entry for the given path
  • Returns true if the path exists
  • Returns all files for the given path, sorted by name
  • Returns the group ID of the owner of this file
  • Returns true if the given path exists and is a directory
  • Returns true if the given path exists and is readonly
  • Returns true if the given path exists and is a file
  • Returns true if the given path exists and is readonly
  • Returns true if the given path exists and is a symlink
  • Returns true if the given path exists and is a symlink pointing to a directory
  • Returns true if the given path exists and is a symlink pointing to a file
  • Creates the given directory and any parent directories needed with the given mode
  • Creates the given directory and any parent directories needed
  • Create an empty file similar to the linux touch command
  • Wraps mkfile allowing for setting the file’s mode.
  • Returns the permissions for a file, directory or link
  • Move a file or directory
  • Returns the (user ID, group ID) of the owner of this file
  • Returns all paths for the given path, sorted by name
  • Attempts to open a file in readonly mode
  • Read all data from the given file and return it as a String
  • Read the given file and returns it as lines in a vector
  • Returns the relative path of the target the link points to
  • Returns the absolute path of the target the link points to
  • Removes the given empty directory or file
  • Removes the given directory after removing all of its contents
  • Returns the current root directory
  • Set the current vfs backend being used
  • Set the current working directory
  • Switch the current vfs provider to Memfs if not already
  • Switch the current vfs provider to Stdfs if not already
  • Creates a new symbolic link
  • Returns the user ID of the owner of this file
  • Opens a file in write-only mode
  • Write the given data to to the target file
  • Write the given lines to to the target file including final newline