Skip to main content

BaseFiler

Struct BaseFiler 

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

Manages file directories and files for KERI installation resources like databases and configuration files.

Filer instances handle the creation and management of directories and files using configurable paths and permissions to store KERI-specific resources.

Implementations§

Source§

impl BaseFiler

Source

pub fn name(&self) -> String

Source

pub fn base(&self) -> String

Source

pub fn path(&self) -> Option<PathBuf>

Source

pub fn temp(&self) -> bool

Source

pub fn filed(&self) -> bool

Source

pub fn opened(&self) -> bool

Source

pub fn extensioned(&self) -> bool

Source

pub fn perm(&self) -> u32

Source§

impl BaseFiler

Source

pub fn new<S1, S2>( name: S1, base: S2, temp: bool, head_dir_path: Option<PathBuf>, perm: Option<u32>, reopen: bool, clear: bool, reuse: bool, clean: bool, filed: bool, extensioned: bool, mode: Option<String>, fext: Option<String>, defaults: Option<FilerDefaults>, ) -> Result<Self, CoreError>
where S1: Into<String>, S2: Into<String>,

Create a new Filer instance.

§Arguments
  • name - Unique identifier of file or directory
  • base - Optional directory path segment inserted before name
  • temp - If true, open in temporary directory, clear on close
  • head_dir_path - Optional head directory pathname for main database
  • perm - Optional numeric os dir permissions for database
  • reopen - If true, (re)open with this init
  • clear - If true, remove directory upon close when reopening
  • reuse - If true, reuse path if already exists
  • clean - If true, path uses clean tail variant
  • filed - If true, path is file path not directory path
  • extensioned - When not filed, if true, ensure path ends with fext
  • mode - File open mode when filed
  • fext - File extension when filed or extensioned
§Returns
  • Result containing a new Filer instance or an error
Source

pub fn reopen( &mut self, temp: Option<bool>, head_dir_path: Option<PathBuf>, perm: Option<u32>, clear: bool, reuse: bool, clean: bool, mode: Option<String>, fext: Option<String>, ) -> Result<bool, CoreError>

Open if closed or close and reopen if opened or create and open if not

§Arguments
  • temp - If provided, set the temp flag
  • head_dir_path - If provided, set the head directory path
  • perm - If provided, set the permissions
  • clear - If true, remove directory upon close
  • reuse - If true, reuse self.path if already exists
  • clean - If true, path uses clean tail variant
  • mode - If provided, set the file open mode when filed
  • fext - If provided, set the file extension when filed
§Returns
  • Result where true means opened, false means closed
Source

pub fn remake( &self, name: &str, base: &str, temp: Option<bool>, head_dir_path: Option<&Path>, perm: Option<u32>, clean: bool, filed: bool, extensioned: bool, mode: Option<&str>, fext: Option<&str>, ) -> Result<(PathBuf, Option<File>), CoreError>

Makes and returns (path, file) by opening or creating and opening if not preexistent, directory or file at path

§Arguments
  • name - Unique name alias portion of path
  • base - Optional base inserted before name in path
  • temp - Optional temp flag:
    • None means ignore
    • Some(true) means open temporary directory, may clear on close
    • Some(false) means open persistent directory, may not clear on close
  • head_dir_path - Optional head directory pathname of main database
  • perm - Directory or file permissions
  • clean - True means make path for cleaned version and remove old directory or file at clean path if any.
  • filed - True means path is file path not directory path
  • extensioned - When not filed: True means ensure path ends with fext False means do not ensure path ends with fext
  • mode - File open mode when filed, such as “w+”
  • fext - File extension when filed
§Returns
  • Result containing a tuple with (PathBuf, Option)
Source

pub fn exists( &self, name: &str, base: &str, head_dir_path: Option<&Path>, clean: bool, filed: bool, extensioned: bool, fext: Option<&str>, ) -> Result<bool, CoreError>

Check if (path. file) exists for a given set of parameters for remake. Temp is not allowed.

§Arguments
  • name - Unique name alias portion of path
  • base - Optional base inserted before name in path
  • head_dir_path - Optional head directory pathname of main database
  • clean - True means make path for cleaned version False means make path normally (not clean)
  • filed - True means path is file path not directory path False means path is directory path not file path
  • extensioned - When not filed: True means ensure path ends with fext False means do not ensure path ends with fext
  • fext - File extension when filed
§Returns
  • Result containing a boolean:
    • true means path or alt path exists
    • false means neither exists
Source

pub fn close(&mut self, clear: bool) -> Result<bool, CoreError>

Close file if any and optionally remove directory or file at path

§Arguments
  • clear - If true, remove the directory or file at path
§Returns
  • Result where true means closed, false means still opened
Source

pub fn open(&mut self) -> Result<()>

Opens or creates the directory and/or file specified by this Filer

Source

pub fn get_path(&self) -> Option<&Path>

Returns the current path if set

Source

pub fn get_file(&self) -> Option<&File>

Returns a reference to the file if opened

Source

pub fn get_file_mut(&mut self) -> Option<&mut File>

Returns a mutable reference to the file if opened

Trait Implementations§

Source§

impl Default for BaseFiler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Filer for BaseFiler

Source§

fn defaults() -> FilerDefaults

Source§

const HEAD_DIR_PATH: &'static str = "/usr/local/var"

Default absolute directory path head such as “/usr/local/var”
Source§

const TAIL_DIR_PATH: &'static str = "keri"

Default relative directory path tail when using head
Source§

const CLEAN_TAIL_DIR_PATH: &'static str = "keri/clean"

Default relative directory path tail when creating clean
Source§

const ALT_TAIL_DIR_PATH: &'static str = ".keri"

Default alternative relative directory path tail as fallback
Source§

const ALT_CLEAN_TAIL_DIR_PATH: &'static str = ".keri/clean"

Default alternative relative path tail when creating clean
Source§

const TEMP_PREFIX: &'static str = "keri_"

Default relative directory path prefix when using temp head
Source§

const TEMP_HEAD_DIR: &'static str = "/tmp"

Default relative directory path prefix when using temp head
Source§

const PERM: u32 = 0o1700

Explicit default octal permissions such as 0o1700
Source§

const MODE: &'static str = "r+"

Open mode such as “r+”
Source§

const FEXT: &'static str = "text"

Default file extension such as “text” for “fname.text”

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.

§

impl<T> Instrument for T

§

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

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

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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