pub struct CapabilityDir { /* private fields */ }Expand description
Handles scoped directory operations relative to a canonical checkout root.
Implementations§
Source§impl CapabilityDir
impl CapabilityDir
Sourcepub fn open(root: &Path) -> Result<Self, CapabilityError>
pub fn open(root: &Path) -> Result<Self, CapabilityError>
Opens one canonical directory without following a symlink root.
§Errors
Returns CapabilityError when the root cannot be canonicalized, is not a directory, or is
a symbolic link.
Sourcepub fn read_utf8_file_bounded(
&self,
relative: &Path,
max_bytes: usize,
) -> Result<String, CapabilityError>
pub fn read_utf8_file_bounded( &self, relative: &Path, max_bytes: usize, ) -> Result<String, CapabilityError>
Reads a bounded UTF-8 file relative to the authorized root.
§Errors
Returns CapabilityError when the relative path is invalid, the file is unsafe, or the
read exceeds max_bytes.
Sourcepub fn read_file_bounded(
&self,
relative: &Path,
max_bytes: usize,
) -> Result<Vec<u8>, CapabilityError>
pub fn read_file_bounded( &self, relative: &Path, max_bytes: usize, ) -> Result<Vec<u8>, CapabilityError>
Reads a bounded file relative to the authorized root.
§Errors
Returns CapabilityError when the relative path is invalid, the file is unsafe, or the
read exceeds max_bytes.
Sourcepub fn classify_regular_file_entry(
&self,
relative: &Path,
) -> Result<RegularFileEntry, CapabilityError>
pub fn classify_regular_file_entry( &self, relative: &Path, ) -> Result<RegularFileEntry, CapabilityError>
Classifies whether a relative path is absent, a regular file, or an unsafe non-regular entry.
§Errors
Returns CapabilityError when the relative path is invalid, a symlink, or unreadable.
Sourcepub fn regular_file_exists(
&self,
relative: &Path,
) -> Result<bool, CapabilityError>
pub fn regular_file_exists( &self, relative: &Path, ) -> Result<bool, CapabilityError>
Returns whether a regular file exists at a relative path.
§Errors
Returns CapabilityError when the relative path is invalid or resolves to an unsafe
entry.
Sourcepub fn atomic_write(
&self,
relative: &Path,
bytes: &[u8],
) -> Result<(), CapabilityError>
pub fn atomic_write( &self, relative: &Path, bytes: &[u8], ) -> Result<(), CapabilityError>
Atomically writes bytes to a relative file, creating parent directories as needed.
§Errors
Returns CapabilityError when the relative path is invalid, a parent is unsafe, or the
write fails.
Sourcepub fn remove_file_if_exists(
&self,
relative: &Path,
) -> Result<bool, CapabilityError>
pub fn remove_file_if_exists( &self, relative: &Path, ) -> Result<bool, CapabilityError>
Removes a regular file relative to the authorized root when it exists.
§Errors
Returns CapabilityError when the relative path is invalid or the target is unsafe.