pub struct RootDir(/* private fields */);
Expand description
Wrapper for a cap_std::fs::Dir
that is defined to use `RESOLVE_IN_ROOT``
semantics when opening files and subdirectories. This currently only
offers a subset of the methods, primarily reading.
§When and how to use this
In general, if your use case possibly involves reading files that may be
absolute symlinks, or relative symlinks that may go outside the provided
directory, you will need to use this API instead of cap_std::fs::Dir
.
§Performing writes
If you want to simultaneously perform other operations (such as writing), at the moment
it requires explicitly maintaining a duplicate copy of a cap_std::fs::Dir
instance, or using direct rustix::fs
APIs.
Implementations§
Source§impl RootDir
impl RootDir
Sourcepub fn new(src: &Dir, path: impl AsRef<Path>) -> Result<Self>
pub fn new(src: &Dir, path: impl AsRef<Path>) -> Result<Self>
Create a new instance from an existing cap_std::fs::Dir
instance.
Sourcepub fn open_ambient_root(
path: impl AsRef<Path>,
authority: AmbientAuthority,
) -> Result<Self>
pub fn open_ambient_root( path: impl AsRef<Path>, authority: AmbientAuthority, ) -> Result<Self>
Create a new instance from an ambient path.
Sourcepub fn open(&self, path: impl AsRef<Path>) -> Result<File>
pub fn open(&self, path: impl AsRef<Path>) -> Result<File>
Open a file in this root, read-only.
Sourcepub fn open_optional(&self, path: impl AsRef<Path>) -> Result<Option<File>>
pub fn open_optional(&self, path: impl AsRef<Path>) -> Result<Option<File>>
Open a file read-only, but return Ok(None)
if it does not exist.
Sourcepub fn read(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>
pub fn read(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>
Read the contents of a file into a vector.
Sourcepub fn read_to_string(&self, path: impl AsRef<Path>) -> Result<String>
pub fn read_to_string(&self, path: impl AsRef<Path>) -> Result<String>
Read the contents of a file as a string.
Sourcepub fn read_dir(&self, path: impl AsRef<Path>) -> Result<ReadDir>
pub fn read_dir(&self, path: impl AsRef<Path>) -> Result<ReadDir>
Return the directory entries of the target subdirectory.
Sourcepub fn reopen_cap_std(&self) -> Result<Dir>
pub fn reopen_cap_std(&self) -> Result<Dir>
Create a cap_std::fs::Dir
pointing to the same directory as self
.
This view will not use RESOLVE_IN_ROOT
.