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§
- assert_
copyfile - Assert the copy of a file
- assert_
exists - Assert that a file or directory exists
- assert_
is_ dir - Assert that the given path exists and is a directory
- assert_
is_ file - Assert that the given path exists and is a file
- assert_
is_ symlink - Assert that the given path exists and is a symlink
- assert_
memfs_ setup - Setup Vfs testing components with Memfs provider
- assert_
mkdir_ m - Assert the creation of the given directory with the given mode
- assert_
mkdir_ p - Assert the creation of the given directory.
- assert_
mkfile - Assert the creation of a file. If the file exists no change is made
- assert_
no_ dir - Assert that the given path isn’t a directory
- assert_
no_ exists - Assert the given path doesn’t exist
- assert_
no_ file - Assert that the given path isn’t a file
- assert_
no_ symlink - Assert that the given path isn’t a symlink
- assert_
read_ all - Assert data read from the file matches the input data
- assert_
readlink - Assert the reading of a link’s target relative path
- assert_
readlink_ abs - Assert the reading of a link’s target absolute path
- assert_
remove - Assert the removal of the target file or directory
- assert_
remove_ all - Assert the removal of the target path
- assert_
setup - Setup Vfs testing components using the current provider is
- assert_
stdfs_ setup - Setup Vfs testing components with Stdfs provider
- assert_
symlink - Assert the creation of a symlink. If the symlink exists no change is made
- assert_
write_ all - Assert data is written to the given file
Structs§
- VFS
- 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§
- abs
- Return the path in an absolute clean form
- all_
dirs - Returns all dirs for the given path recursively
- all_
files - Returns all files for the given path recursively
- all_
paths - Returns all paths for the given path recursively
- append
- Opens a file in append mode
- append_
all - Append the given data to to the target file
- append_
line - Append the given line to to the target file including a newline
- append_
lines - Append the given lines to to the target file including newlines
- chmod
- Change all file/dir permissions recursivly to
mode - chmod_b
- Returns a new
Chmodbuilder for advanced chmod options - chown
- Change the ownership of the path recursivly
- chown_b
- Creates new
Chownfor use with the builder pattern - config_
dir - Returns the highest priority active configuration directory.
- copy
- Copies src to dst recursively
- copy_b
- Creates a new
Copierfor use with the builder pattern - cwd
- Returns the current working directory
- dirs
- Returns all directories for the given path, sorted by name
- entries
- Returns an iterator over the given path
- entry
- Return a virtual filesystem entry for the given path
- exists
- Returns true if the
pathexists - files
- Returns all files for the given path, sorted by name
- gid
- Returns the group ID of the owner of this file
- is_dir
- Returns true if the given path exists and is a directory
- is_exec
- Returns true if the given path exists and is readonly
- is_file
- Returns true if the given path exists and is a file
- is_
readonly - Returns true if the given path exists and is readonly
- is_
symlink - Returns true if the given path exists and is a symlink
- is_
symlink_ dir - Returns true if the given path exists and is a symlink pointing to a directory
- is_
symlink_ file - Returns true if the given path exists and is a symlink pointing to a file
- mkdir_m
- Creates the given directory and any parent directories needed with the given mode
- mkdir_p
- Creates the given directory and any parent directories needed
- mkfile
- Create an empty file similar to the linux touch command
- mkfile_
m - Wraps
mkfileallowing for setting the file’s mode. - mode
- Returns the permissions for a file, directory or link
- move_p
- Move a file or directory
- owner
- Returns the (user ID, group ID) of the owner of this file
- paths
- Returns all paths for the given path, sorted by name
- read
- Attempts to open a file in readonly mode
- read_
all - Read all data from the given file and return it as a String
- read_
lines - Read the given file and returns it as lines in a vector
- readlink
- Returns the relative path of the target the link points to
- readlink_
abs - Returns the absolute path of the target the link points to
- remove
- Removes the given empty directory or file
- remove_
all - Removes the given directory after removing all of its contents
- root
- Returns the current root directory
- set
- Set the current vfs backend being used
- set_cwd
- Set the current working directory
- set_
memfs - Switch the current vfs provider to Memfs if not already
- set_
stdfs - Switch the current vfs provider to Stdfs if not already
- symlink
- Creates a new symbolic link
- uid
- Returns the user ID of the owner of this file
- write
- Opens a file in write-only mode
- write_
all - Write the given data to to the target file
- write_
lines - Write the given lines to to the target file including final newline