pub struct PathCache {
pub unlink_on_collision: bool,
pub test_mkdir_calls: usize,
/* private fields */
}
Expand description
A cache for directory creation to reduce the amount of stat calls when creating directories safely, that is without following symlinks that might be on the way.
As a special case, it offers a ‘prefix’ which (by itself) is assumed to exist and may contain symlinks. Everything past that prefix boundary must not contain a symlink. We do this by allowing any input path.
Another added benefit is its ability to store the path of full path of the entry to which leading directories are to be created to avoid allocating memory.
For this to work, it remembers the last ‘good’ path to a directory and assumes that all components of it are still valid, too. As directories are created, the cache will be adjusted to reflect the latest seen directory.
The caching is only useful if consecutive calls to create a directory are using a sorted list of entries.
Fields
unlink_on_collision: bool
If there is a symlink or a file in our path, try to unlink it before creating the directory.
test_mkdir_calls: usize
just for testing
Implementations
sourceimpl PathCache
impl PathCache
sourcepub fn new(root: impl Into<PathBuf>) -> Self
pub fn new(root: impl Into<PathBuf>) -> Self
Create a new instance with root
being the base for all future paths we handle, assuming it to be valid which includes
symbolic links to be included in it as well.
sourcepub fn append_relative_path_assure_leading_dir(
&mut self,
relative: impl AsRef<Path>,
mode: Mode
) -> Result<&Path>
pub fn append_relative_path_assure_leading_dir(
&mut self,
relative: impl AsRef<Path>,
mode: Mode
) -> Result<&Path>
Append the relative
path to the root directory the cache contains and efficiently create leading directories
unless mode
indicates relative
points to a directory itself in which case the entire resulting path is created as directory.
The full path to relative
will be returned for use on the file system.
Auto Trait Implementations
impl RefUnwindSafe for PathCache
impl Send for PathCache
impl Sync for PathCache
impl Unpin for PathCache
impl UnwindSafe for PathCache
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more