Struct quickcfg::FileSystem
source · pub struct FileSystem<'a> { /* private fields */ }
Expand description
Helper and tracker of any filesystem modifications.
Implementations§
source§impl<'a> FileSystem<'a>
impl<'a> FileSystem<'a>
sourcepub fn new(
opts: &'a Opts,
state_dir: &Path,
allocator: &'a UnitAllocator,
data: &'a Data
) -> FileSystem<'a>
pub fn new( opts: &'a Opts, state_dir: &Path, allocator: &'a UnitAllocator, data: &'a Data ) -> FileSystem<'a>
Create new, thread-safe file utilities.
sourcepub fn validate(self) -> Result<(), Error>
pub fn validate(self) -> Result<(), Error>
Validate that we haven’t created any conflicting files. Logs details and errors in case duplicates are registered.
sourcepub fn file_dependency(&self, path: &Path) -> Result<Dependency, Error>
pub fn file_dependency(&self, path: &Path) -> Result<Dependency, Error>
Access or allocate a file dependency of the given path.
sourcepub fn dir_dependency(&self, path: &Path) -> Result<Dependency, Error>
pub fn dir_dependency(&self, path: &Path) -> Result<Dependency, Error>
Access or allocate a directory dependency of the given path.
sourcepub fn symlink(
&self,
path: &Path,
link: PathBuf,
meta: Option<&Metadata>
) -> Result<Option<SystemUnit>, Error>
pub fn symlink( &self, path: &Path, link: PathBuf, meta: Option<&Metadata> ) -> Result<Option<SystemUnit>, Error>
Try to create a symlink.
sourcepub fn copy_file(
&self,
from: &Path,
from_meta: Metadata,
to: &Path,
to_meta: Option<&Metadata>,
template: bool
) -> Result<Option<SystemUnit>, Error>
pub fn copy_file( &self, from: &Path, from_meta: Metadata, to: &Path, to_meta: Option<&Metadata>, template: bool ) -> Result<Option<SystemUnit>, Error>
Optionally set up if we should copy a file.
This is true if:
- The destination file does not exist.
- The destination file has a modified timestamp less than the source file.
sourcepub fn create_dir_all(&self, dir: &Path) -> Result<Vec<SystemUnit>, Error>
pub fn create_dir_all(&self, dir: &Path) -> Result<Vec<SystemUnit>, Error>
Recursively set up units with dependencies to create the given directories.
sourcepub fn state_path(&self, id: &str) -> PathBuf
pub fn state_path(&self, id: &str) -> PathBuf
Get the state path for the given ID.
sourcepub fn try_open_meta(p: &Path) -> Result<Option<Metadata>, Error>
pub fn try_open_meta(p: &Path) -> Result<Option<Metadata>, Error>
Try to open metadata, unless the file does not exist.
If the file does not exist, returns None
.
sourcepub fn should_create_dir(
path: &Path,
meta: Option<&Metadata>
) -> Result<bool, Error>
pub fn should_create_dir( path: &Path, meta: Option<&Metadata> ) -> Result<bool, Error>
Test if we should create the destination directory.
sourcepub fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf>
pub fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf>
Construct a relative path from a provided base directory path to the provided path
use quickcfg::FileSystem;
use std::path::PathBuf;
let baz: PathBuf = "/foo/bar/baz".into();
let bar: PathBuf = "/foo/bar".into();
let quux: PathBuf = "/foo/bar/quux".into();
assert_eq!(FileSystem::path_relative_from(&bar, &baz), Some("../".into()));
assert_eq!(FileSystem::path_relative_from(&baz, &bar), Some("baz".into()));
assert_eq!(FileSystem::path_relative_from(&quux, &baz), Some("../quux".into()));
assert_eq!(FileSystem::path_relative_from(&baz, &quux), Some("../baz".into()));
assert_eq!(FileSystem::path_relative_from(&bar, &quux), Some("../".into()));