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§
- All essential symbols in a simple consumable form
Macros§
- Assert the copy of a file
- Assert that a file or directory exists
- Assert that the given path exists and is a directory
- Assert that the given path exists and is a file
- Assert that the given path exists and is a symlink
- Setup Vfs testing components with Memfs provider
- Assert the creation of the given directory with the given mode
- Assert the creation of the given directory.
- Assert the creation of a file. If the file exists no change is made
- Assert that the given path isn’t a directory
- Assert the given path doesn’t exist
- Assert that the given path isn’t a file
- Assert that the given path isn’t a symlink
- Assert data read from the file matches the input data
- Assert the reading of a link’s target relative path
- Assert the reading of a link’s target absolute path
- Assert the removal of the target file or directory
- Assert the removal of the target path
- Setup Vfs testing components using the current provider is
- Setup Vfs testing components with Stdfs provider
- Assert the creation of a symlink. If the symlink exists no change is made
- Assert data is written to the given file
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