Skip to main content

StateDir

Struct StateDir 

Source
pub struct StateDir { /* private fields */ }

Implementations§

Source§

impl StateDir

Source

pub fn open(path: &Path) -> Result<Self>

Pin an existing directory.

Source

pub fn create(path: &Path) -> Result<Self>

Create the directory (and missing ancestors, owner-only, through descriptor-relative mkdirat) if needed, then pin it.

Source

pub fn create_in_resolved_parent(path: &Path) -> Result<Self>

Like create but resolves symlinks in the parent first (for example macOS /var -> /private/var). The final component must still be a real directory.

Source

pub fn path(&self) -> &Path

Source

pub fn child(&self, name: &str) -> Result<StateDir>

Create-or-open a direct child directory (owner-only), pinned relative to this one.

Source

pub fn stat(&self, name: &str) -> Result<Option<EntryStat>>

Source

pub fn exists(&self, name: &str) -> Result<bool>

Source

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

Read a regular file (never through a symlink), refusing anything over max_bytes.

Source

pub fn read_opt(&self, name: &str, max_bytes: u64) -> Result<Option<Vec<u8>>>

Like read but Ok(None) when the entry does not exist.

Source

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

Atomically create or replace name (owner-only, fsynced file and directory).

Source

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

Atomically create name, failing with FsError::AlreadyExists rather than replacing.

Source

pub fn remove(&self, name: &str) -> Result<bool>

Remove a file. Unix removes a symlink itself; Windows refuses reparse points. Missing is Ok(false).

Source

pub fn list(&self, limit: usize) -> Result<Vec<String>>

Names of direct children, capped at limit entries (error past the cap).

Source

pub fn sweep_temps(&self, max_age: Duration) -> Result<usize>

Remove temp files left by writers that were killed mid-write (pid gone, or older than max_age). Returns how many were removed.

Trait Implementations§

Source§

impl Debug for StateDir

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.