pub struct WorkdirRoot { /* private fields */ }Expand description
A held directory descriptor inside (or at) the accessible workdir, and the only way the runtime reads its own decisions from, or writes into, that tree.
Cheap to clone. Every clone of the accessible root and of the session root derived from it shares one refusal latch.
Implementations§
Source§impl WorkdirRoot
impl WorkdirRoot
Sourcepub fn open(path: &Path) -> Result<Self, WorkdirError>
pub fn open(path: &Path) -> Result<Self, WorkdirError>
Opens the accessible workdir at path.
path is the operator’s choice (--workdir, or the directory the runtime created under
the manifest directory) and is resolved as given, links above it included. Nothing below
it is ever resolved by path again.
Sourcepub fn open_beneath(&self, rel: &str) -> Result<Option<Self>, WorkdirError>
pub fn open_beneath(&self, rel: &str) -> Result<Option<Self>, WorkdirError>
The existing directory rel beneath this root as a root of its own, reached with no link
followed and sharing this root’s latch, or None when it or a parent is absent.
Sourcepub fn open_sharing_latch(
path: &Path,
latch_of: &WorkdirRoot,
) -> Result<Self, WorkdirError>
pub fn open_sharing_latch( path: &Path, latch_of: &WorkdirRoot, ) -> Result<Self, WorkdirError>
Self::open, sharing latch_of’s refusal latch: for a directory outside the accessible
workdir whose refusals still fail this session’s task. Its refusals name paths relative to
path itself.
Sourcepub fn open_sharing_latch_absolute(
path: &Path,
latch_of: &WorkdirRoot,
) -> Result<Self, WorkdirError>
pub fn open_sharing_latch_absolute( path: &Path, latch_of: &WorkdirRoot, ) -> Result<Self, WorkdirError>
Self::open_sharing_latch, with every refusal and error naming its path as
<path>/<rel>: for a directory outside the workdir that an operator reads about by its
absolute path, such as the session’s runtime directory.
Sourcepub fn identity(&self) -> Result<(u64, u64), WorkdirError>
pub fn identity(&self) -> Result<(u64, u64), WorkdirError>
(st_dev, st_ino) of this root’s directory, from fstat on the held descriptor.
Sourcepub fn dir_fd(&self) -> Result<OwnedFd, WorkdirError>
pub fn dir_fd(&self) -> Result<OwnedFd, WorkdirError>
A fresh read-only directory descriptor for this root’s own directory, reopened from the
held descriptor with no path lookup, for *at calls the root has no method for.
Sourcepub fn path_fd(&self) -> Result<OwnedFd, WorkdirError>
pub fn path_fd(&self) -> Result<OwnedFd, WorkdirError>
An O_PATH | O_DIRECTORY descriptor for this root’s own directory, reopened from the held
descriptor with no path lookup: a Landlock rule’s fd, or a bind source through
/proc/self/fd/<n>.
Sourcepub fn path_fd_beneath(
&self,
rel: impl AsRef<Path>,
) -> Result<OwnedFd, WorkdirError>
pub fn path_fd_beneath( &self, rel: impl AsRef<Path>, ) -> Result<OwnedFd, WorkdirError>
An O_PATH | O_DIRECTORY | O_NOFOLLOW descriptor for the existing directory rel,
reached by the same no-follow walk every other call takes. A link at any segment is
refused and latched; a missing directory is a NotFound I/O error.
Sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
This root’s host path, for display, a subprocess argument, a Landlock rule or a bind
source. The runtime never opens it through std.
Sourcepub fn host_path(&self, rel: impl AsRef<Path>) -> PathBuf
pub fn host_path(&self, rel: impl AsRef<Path>) -> PathBuf
The host path of rel beneath this root, on Self::path’s terms.
Sourcepub fn display_path(&self, rel: impl AsRef<Path>) -> String
pub fn display_path(&self, rel: impl AsRef<Path>) -> String
rel relative to the accessible workdir, the form every refusal and error uses.
Sourcepub fn owner(&self) -> Result<(u32, u32), WorkdirError>
pub fn owner(&self) -> Result<(u32, u32), WorkdirError>
The uid and gid that own this root’s directory, from fstat on the held descriptor.
Sourcepub fn take_refusals(&self) -> Vec<WorkdirRefusal>
pub fn take_refusals(&self) -> Vec<WorkdirRefusal>
Every refusal latched since the last call, on any clone of either root, oldest first.
Sourcepub fn write_file(
&self,
rel: impl AsRef<Path>,
bytes: &[u8],
mode: u32,
) -> Result<(), WorkdirError>
pub fn write_file( &self, rel: impl AsRef<Path>, bytes: &[u8], mode: u32, ) -> Result<(), WorkdirError>
Writes bytes to rel through a same-directory temporary file renamed over it.
Missing parent directories are created with DEFAULT_DIR_MODE. A link at rel when the
call starts is refused; one planted after that check is replaced by the rename, never
followed. A directory at rel is an I/O error. The temporary file
.<name>.<uuid v7 simple>.tmp is removed on any failure.
Sourcepub fn write_file_exact_mode(
&self,
rel: impl AsRef<Path>,
bytes: &[u8],
mode: u32,
) -> Result<(), WorkdirError>
pub fn write_file_exact_mode( &self, rel: impl AsRef<Path>, bytes: &[u8], mode: u32, ) -> Result<(), WorkdirError>
Self::write_file, with the file’s mode set to exactly mode — fchmod on the
temporary file before the rename — rather than mode less the umask.
Sourcepub fn overwrite_in_place(
&self,
rel: impl AsRef<Path>,
bytes: &[u8],
mode: u32,
) -> Result<(), WorkdirError>
pub fn overwrite_in_place( &self, rel: impl AsRef<Path>, bytes: &[u8], mode: u32, ) -> Result<(), WorkdirError>
Truncates and rewrites the regular file at rel in place, creating it with mode if
absent, so its inode survives — what a Landlock rule bound to that inode needs.
A link, a non-regular file or a file with more than one hard link at rel is refused.
Sourcepub fn open_append(
&self,
rel: impl AsRef<Path>,
mode: u32,
) -> Result<File, WorkdirError>
pub fn open_append( &self, rel: impl AsRef<Path>, mode: u32, ) -> Result<File, WorkdirError>
Opens rel for appending, creating it with mode and its parents with
DEFAULT_DIR_MODE if absent.
Refused when rel is a link, is not a regular file, or is a regular file with more than
one hard link — the last because a hard link to a host file would otherwise be appended to.
Sourcepub fn read_file(
&self,
rel: impl AsRef<Path>,
max_bytes: u64,
) -> Result<Option<Vec<u8>>, WorkdirError>
pub fn read_file( &self, rel: impl AsRef<Path>, max_bytes: u64, ) -> Result<Option<Vec<u8>>, WorkdirError>
The bytes of the regular file at rel, or None when it or a parent is absent.
Refused when rel or a parent is a link, or rel is not a regular file; a FIFO is
refused without blocking. A file longer than max_bytes is an InvalidData error.
Sourcepub fn read_to_string(
&self,
rel: impl AsRef<Path>,
) -> Result<Option<String>, WorkdirError>
pub fn read_to_string( &self, rel: impl AsRef<Path>, ) -> Result<Option<String>, WorkdirError>
Self::read_file with no size bound, decoded as UTF-8.
Sourcepub fn create_dir_all(
&self,
rel: impl AsRef<Path>,
mode: u32,
) -> Result<(), WorkdirError>
pub fn create_dir_all( &self, rel: impl AsRef<Path>, mode: u32, ) -> Result<(), WorkdirError>
Creates rel and every missing parent. mode applies to each directory this call
creates (less the umask); an existing one keeps its mode. A link at any segment is refused.
Sourcepub fn set_dir_mode(
&self,
rel: impl AsRef<Path>,
mode: u32,
) -> Result<(), WorkdirError>
pub fn set_dir_mode( &self, rel: impl AsRef<Path>, mode: u32, ) -> Result<(), WorkdirError>
Sets the mode of the existing directory rel to exactly mode & 0o7777. A link at rel
or at any parent is refused, so the mode lands only on a directory inside the root.
Sourcepub fn entry_kind(
&self,
rel: impl AsRef<Path>,
) -> Result<Option<EntryKind>, WorkdirError>
pub fn entry_kind( &self, rel: impl AsRef<Path>, ) -> Result<Option<EntryKind>, WorkdirError>
What fstatat(AT_SYMLINK_NOFOLLOW) finds at rel, or None when it or a parent is
absent. A link at a parent is refused; a link at rel itself is reported as
EntryKind::Symlink for the caller to refuse.
Sourcepub fn file_len(
&self,
rel: impl AsRef<Path>,
) -> Result<Option<u64>, WorkdirError>
pub fn file_len( &self, rel: impl AsRef<Path>, ) -> Result<Option<u64>, WorkdirError>
Size in bytes of the regular file at rel, or None when it or a parent is absent or it
is not a regular file. A link at any segment is refused.
Sourcepub fn list_dir(
&self,
rel: impl AsRef<Path>,
) -> Result<Option<Vec<(String, EntryKind)>>, WorkdirError>
pub fn list_dir( &self, rel: impl AsRef<Path>, ) -> Result<Option<Vec<(String, EntryKind)>>, WorkdirError>
The entries of the directory rel ("" for this root itself) with what each is, sorted by
name, or None when it or a parent is absent. A link at any segment of rel is refused;
a link inside it is listed as EntryKind::Symlink.
Sourcepub fn remove_file(&self, rel: impl AsRef<Path>) -> Result<(), WorkdirError>
pub fn remove_file(&self, rel: impl AsRef<Path>) -> Result<(), WorkdirError>
Unlinks the file at rel. A link at rel or at a parent is refused rather than removed,
so the refusal is recorded.
Sourcepub fn remove_dir_all(&self, rel: impl AsRef<Path>) -> Result<(), WorkdirError>
pub fn remove_dir_all(&self, rel: impl AsRef<Path>) -> Result<(), WorkdirError>
Removes the directory rel and everything in it, by descriptor: each child directory is
opened no-follow from its parent’s descriptor, so no part of the removal resolves a path
from the root. A link at rel or at a parent is refused; a link inside is unlinked, not
followed. Each directory is given owner rwx before it is emptied, so one a command left
unreadable or unwritable is removed too.
Trait Implementations§
Source§impl Clone for WorkdirRoot
impl Clone for WorkdirRoot
Auto Trait Implementations§
impl Forget for WorkdirRoot
impl Freeze for WorkdirRoot
impl RefUnwindSafe for WorkdirRoot
impl Send for WorkdirRoot
impl Sync for WorkdirRoot
impl Unpin for WorkdirRoot
impl UnsafeUnpin for WorkdirRoot
impl UnwindSafe for WorkdirRoot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more