Skip to main content

DataDir

Struct DataDir 

Source
pub struct DataDir { /* private fields */ }
Expand description

A capability handle to a base directory.

Every relative path passed to a method is resolved against the base and cannot escape it.

Implementations§

Source§

impl DataDir

Source

pub fn open(base: impl AsRef<Path>) -> Result<Self>

Open an existing base directory.

This is the single place ambient filesystem authority enters the capability boundary.

Source

pub fn open_or_create(base: impl AsRef<Path>) -> Result<Self>

Open a base directory, first creating it (and any missing parents) with ambient authority.

The base path is the trust boundary, not attacker input, so creating it ambiently is intentional; everything joined onto the returned handle afterwards stays confined.

Source

pub fn resolve(&self, rel: &str) -> PathBuf

Absolute path of a confined relative path, for logging and return values only.

The result is never re-opened through ambient authority — all filesystem access goes through the capability-scoped Dir. This is purely a display/identity helper.

Source

pub fn read_to_string(&self, rel: &str) -> Result<String>

Read a confined relative path to a String.

Source

pub fn read(&self, rel: &str) -> Result<Vec<u8>>

Read a confined relative path to bytes.

Source

pub fn create_dir_all(&self, rel: &str) -> Result<()>

Create all directories along a confined relative path.

Source

pub fn exists(&self, rel: &str) -> bool

Whether a confined relative path exists.

Source

pub fn file_len(&self, rel: &str) -> Result<u64>

Length in bytes of a confined relative file.

Source

pub fn subdir(&self, rel: &str) -> Result<Self>

Open a confined relative subdirectory as its own capability handle.

Source

pub fn write(&self, rel: &str, bytes: &[u8]) -> Result<()>

Write bytes to a confined relative path, creating or truncating it.

Source

pub fn write_atomic(&self, rel: &str, bytes: &[u8]) -> Result<()>

Atomically replace a confined relative path.

Writes to a sibling temp file inside the same Dir, fsyncs, then renames over the target. Both the temp file and the rename are *at-relative to the open base fd, so neither can escape it.

Source

pub fn remove_file(&self, rel: &str) -> Result<()>

Remove a confined relative file.

Source

pub fn walk_files(&self) -> Result<Vec<String>>

Recursively collect the relative paths of every regular file under the base directory.

Each directory level is descended through its own re-opened Dir handle, so the walk never round-trips a path back through ambient authority. Symlinks, sockets, and devices are reported via file_type() and never followed — the walk cannot escape the base.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more