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

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.

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.