Skip to main content

miden_node_store/
data_directory.rs

1use std::ops::Not;
2use std::path::PathBuf;
3
4use miden_node_tracing::RecordAttribute;
5
6/// Represents the store's data-directory and its content paths.
7///
8/// Used to keep our filepath assumptions in one location.
9#[derive(Clone)]
10pub struct DataDirectory(PathBuf);
11
12impl DataDirectory {
13    /// Creates a new [`DataDirectory`], ensuring that the directory exists and is accessible
14    /// insofar as is possible.
15    pub fn load(path: PathBuf) -> std::io::Result<Self> {
16        let meta = fs_err::metadata(&path)?;
17        if meta.is_dir().not() {
18            return Err(std::io::ErrorKind::NotConnected.into());
19        }
20
21        Ok(Self(path))
22    }
23
24    pub fn block_store_dir(&self) -> PathBuf {
25        self.0.join("blocks")
26    }
27
28    pub fn database_path(&self) -> PathBuf {
29        self.0.join("miden-store.sqlite3")
30    }
31
32    pub fn display(&self) -> std::path::Display<'_> {
33        self.0.display()
34    }
35}
36
37impl RecordAttribute for DataDirectory {
38    const FIELD_NAMES: &'static [&'static str] = &["data.directory", "path"];
39
40    fn record_attribute(&self) -> impl miden_node_tracing::Value + '_ {
41        miden_node_tracing::field::display(self.display())
42    }
43}