Skip to main content

miden_node_store/
data_directory.rs

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