Struct tor_persist::FsStateMgr
source · pub struct FsStateMgr { /* private fields */ }Expand description
Implementation of StateMgr that stores state as JSON files on disk.
Locking
This manager uses a lock file to determine whether it’s allowed to write to the disk. Only one process should write to the disk at a time, though any number may read from the disk.
By default, every FsStateMgr starts out unlocked, and only able
to read. Use FsStateMgr::try_lock() to lock it.
Limitations
-
This manager only accepts objects that can be serialized as JSON documents. Some types (like maps with non-string keys) can’t be serialized as JSON.
-
This manager normalizes keys to an fs-safe format before saving data with them. This keeps you from accidentally creating or reading files elsewhere in the filesystem, but it doesn’t prevent collisions when two keys collapse to the same fs-safe filename. Therefore, you should probably only use ascii keys that are fs-safe on all systems.
NEVER use user-controlled or remote-controlled data for your keys.
Implementations§
source§impl FsStateMgr
impl FsStateMgr
sourcepub fn from_path_and_mistrust<P: AsRef<Path>>(
path: P,
mistrust: &Mistrust
) -> Result<Self, Error>
pub fn from_path_and_mistrust<P: AsRef<Path>>( path: P, mistrust: &Mistrust ) -> Result<Self, Error>
Construct a new FsStateMgr to store data in path.
This function will try to create path if it does not already
exist.
All files must be “private” according to the rules specified in mistrust.
sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
Return the top-level directory for this storage manager.
(This is the same directory passed to
FsStateMgr::from_path_and_mistrust.)
Trait Implementations§
source§impl Clone for FsStateMgr
impl Clone for FsStateMgr
source§fn clone(&self) -> FsStateMgr
fn clone(&self) -> FsStateMgr
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for FsStateMgr
impl Debug for FsStateMgr
source§impl StateMgr for FsStateMgr
impl StateMgr for FsStateMgr
source§fn try_lock(&self) -> Result<LockStatus, Error>
fn try_lock(&self) -> Result<LockStatus, Error>
source§fn unlock(&self) -> Result<(), Error>
fn unlock(&self) -> Result<(), Error>
source§fn load<D>(&self, key: &str) -> Result<Option<D>, Error>where
D: DeserializeOwned,
fn load<D>(&self, key: &str) -> Result<Option<D>, Error>where D: DeserializeOwned,
key from the store. Read moresource§fn create_handle<T>(self, key: impl Into<String>) -> DynStorageHandle<T>where
Self: Send + Sync + Sized + 'static,
T: Serialize + DeserializeOwned + 'static,
fn create_handle<T>(self, key: impl Into<String>) -> DynStorageHandle<T>where Self: Send + Sync + Sized + 'static, T: Serialize + DeserializeOwned + 'static,
StorageHandle to store values of particular type
at a particular key.