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()));
Auto Trait Implementations§
impl<'a> !Freeze for FileSystem<'a>
impl<'a> RefUnwindSafe for FileSystem<'a>
impl<'a> Send for FileSystem<'a>
impl<'a> Sync for FileSystem<'a>
impl<'a> Unpin for FileSystem<'a>
impl<'a> UnwindSafe for FileSystem<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more