pub struct SourceRoot { /* private fields */ }Expand description
A source tree root. The root itself may be a link; nothing beneath it is followed.
Implementations§
Source§impl SourceRoot
impl SourceRoot
Sourcepub fn new(root: &Path) -> Self
pub fn new(root: &Path) -> Self
Opens the root. On Unix the directory is opened here, and every later access goes through that handle, so moving or replacing what the path names afterwards does not move the root; elsewhere the path is resolved to an absolute one here.
Sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
The path supplied when this root was opened, for display only. It may be relative, moved or replaced; using it to reopen the tree does not preserve this root’s identity. Access files through this root instead.
Sourcepub fn exists(&self, path: &str) -> Result<bool, AccessError>
pub fn exists(&self, path: &str) -> Result<bool, AccessError>
What is at path, not following it, if anything: as the file
system finds it by that name, which on one that ignores case, or as
on Windows drops trailing dots, can be an entry named otherwise.
A path through a file names nothing; a link on the way is an error.
Sourcepub fn read(
&self,
path: &str,
limit: u64,
) -> Result<Option<Vec<u8>>, AccessError>
pub fn read( &self, path: &str, limit: u64, ) -> Result<Option<Vec<u8>>, AccessError>
Reads a regular file of at most limit bytes. Ok(None) means the
file, or a directory on its way, is missing.
Sourcepub fn directory(
&self,
path: &str,
create: bool,
) -> Result<Option<SourceDirectory>, AccessError>
pub fn directory( &self, path: &str, create: bool, ) -> Result<Option<SourceDirectory>, AccessError>
Opens the directory path (the empty path is the root), creating it
and its missing parents when create. Ok(None) means it is missing
and was not created.
Sourcepub fn make_directory(&self, path: &str) -> Result<bool, AccessError>
pub fn make_directory(&self, path: &str) -> Result<bool, AccessError>
Makes the directory path in its existing parent. Returns whether
this call made it: false when something by that name was already
there, which the caller then did not create.
Sourcepub fn names(
&self,
path: &str,
limit: usize,
) -> Result<Option<(BTreeSet<String>, usize)>, AccessError>
pub fn names( &self, path: &str, limit: usize, ) -> Result<Option<(BTreeSet<String>, usize)>, AccessError>
The UTF-8 names of the entries of the directory path, links
included, and how many entries it has, those whose names are not
UTF-8 included; None when it is missing. A directory with more
than limit entries is an error, AccessError::TooLarge.
Sourcepub fn lock(&self) -> Result<SourceLock, AccessError>
pub fn lock(&self) -> Result<SourceLock, AccessError>
Takes the root’s exclusive lock, held until the returned value is
dropped. It fails at once with AccessError::Locked if another
holder, in this process or another, has it. On Unix it is an
advisory flock of the root directory; on Windows the file
LOCK_NAME in the root, created afresh, shared with no one and
deleted when the lock is released or its process stops, so a file by
that name that no one holds is an error. Elsewhere there is no lock
and this always succeeds.