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 const fn new(root: &'a Path, dir: &'a Path) -> Self
pub const 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 write_base(&self) -> PathBuf
pub fn write_base(&self) -> PathBuf
The directory that the writes must stay in, from
cache_write_base.
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. Use it only for a cache that fallow can build again.
§Errors
Returns the error of the check, of the directory creation, or of the write.
Sourcepub fn write_file_synced(&self, name: &str, data: &[u8]) -> Result<()>
pub fn write_file_synced(&self, name: &str, data: &[u8]) -> Result<()>
Self::write_file through crate::atomic_file::write_atomic_synced,
for data that fallow cannot build again.
§Errors
Returns the errors of Self::write_file.
Sourcepub fn read_file(
&self,
name: &str,
max_bytes: u64,
) -> Result<Vec<u8>, ReadRefusal>
pub fn read_file( &self, name: &str, max_bytes: u64, ) -> Result<Vec<u8>, ReadRefusal>
Read the file name of the cache directory in full, through
crate::read_guard::read_bytes_inside with the base of
Self::write_base as the root.
A cache directory is a path in the checkout, so a clone can hold a
cache file. The read refuses a file that resolves outside the base,
a file that is not a regular file, and a file of more than
max_bytes bytes, before it reads a byte.
§Errors
Returns a crate::read_guard::ReadRefusal when a check fails or
the read fails. A missing file gives a refusal whose
crate::read_guard::ReadRefusal::is_not_found is true.
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.