pub struct CacheTarget<'a> { /* private fields */ }Expand description
A cache directory and the directory that its writes must stay in.
Every cache writer takes this type instead of a bare directory, so a writer cannot skip the symlink check.
Implementations§
Source§impl<'a> CacheTarget<'a>
impl<'a> CacheTarget<'a>
Sourcepub fn new(root: &'a Path, dir: &'a Path) -> Self
pub fn new(root: &'a Path, dir: &'a Path) -> Self
The cache directory dir of the project at root.
Sourcepub const fn inside(dir: &'a Path) -> Self
pub const fn inside(dir: &'a Path) -> Self
A cache directory that is its own base, such as a directory that the user chose.
Sourcepub const fn with_dir(&self, dir: &'a Path) -> Self
pub const fn with_dir(&self, dir: &'a Path) -> Self
The same base with dir as the cache directory, for a subdirectory.
Sourcepub fn check(&self, path: &Path) -> Result<()>
pub fn check(&self, path: &Path) -> Result<()>
Fail when a write to path would follow a symlink that leaves the
base.
§Errors
Returns the error of ensure_no_outside_link.
Sourcepub fn write_file(&self, name: &str, data: &[u8]) -> Result<()>
pub fn write_file(&self, name: &str, data: &[u8]) -> Result<()>
Create the cache directory and replace the file name in it with
data through crate::atomic_file::write_atomic, after the
symlink check.
§Errors
Returns the error of the check, of the directory creation, or of the write.
Sourcepub fn write_gitignore(&self) -> Result<()>
pub fn write_gitignore(&self) -> Result<()>
Write .gitignore with *, so the cache directory is never
committed. An equal file stays as it is.
§Errors
Returns the error of Self::write_file.