pub struct StateDir { /* private fields */ }Implementations§
Source§impl StateDir
impl StateDir
Sourcepub fn create(path: &Path) -> Result<Self>
pub fn create(path: &Path) -> Result<Self>
Create the directory (and missing ancestors, owner-only, through descriptor-relative
mkdirat) if needed, then pin it.
Sourcepub fn create_in_resolved_parent(path: &Path) -> Result<Self>
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.
pub fn path(&self) -> &Path
Sourcepub fn child(&self, name: &str) -> Result<StateDir>
pub fn child(&self, name: &str) -> Result<StateDir>
Create-or-open a direct child directory (owner-only), pinned relative to this one.
pub fn stat(&self, name: &str) -> Result<Option<EntryStat>>
pub fn exists(&self, name: &str) -> Result<bool>
Sourcepub fn read(&self, name: &str, max_bytes: u64) -> Result<Vec<u8>>
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.
Sourcepub fn read_opt(&self, name: &str, max_bytes: u64) -> Result<Option<Vec<u8>>>
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.
Sourcepub fn write(&self, name: &str, bytes: &[u8]) -> Result<()>
pub fn write(&self, name: &str, bytes: &[u8]) -> Result<()>
Atomically create or replace name (owner-only, fsynced file and directory).
Sourcepub fn write_new(&self, name: &str, bytes: &[u8]) -> Result<()>
pub fn write_new(&self, name: &str, bytes: &[u8]) -> Result<()>
Atomically create name, failing with FsError::AlreadyExists rather than replacing.
Sourcepub fn remove(&self, name: &str) -> Result<bool>
pub fn remove(&self, name: &str) -> Result<bool>
Remove a file. Unix removes a symlink itself; Windows refuses reparse points.
Missing is Ok(false).
Sourcepub fn list(&self, limit: usize) -> Result<Vec<String>>
pub fn list(&self, limit: usize) -> Result<Vec<String>>
Names of direct children, capped at limit entries (error past the cap).
Sourcepub fn sweep_temps(&self, max_age: Duration) -> Result<usize>
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.