dbx_core/storage/
manager.rs1use std::fs;
2use std::io;
3use std::path::{Path, PathBuf};
4use tracing::info;
5
6#[derive(Debug, Clone)]
11pub struct StoragePathManager {
12 root_dir: PathBuf,
13}
14
15impl StoragePathManager {
16 pub fn new<P: AsRef<Path>>(root: P) -> Self {
18 Self {
19 root_dir: root.as_ref().to_path_buf(),
20 }
21 }
22
23 pub fn root_dir(&self) -> &Path {
25 &self.root_dir
26 }
27
28 pub fn wos_dir(&self) -> io::Result<PathBuf> {
30 let p = self.root_dir.join("wos");
31 fs::create_dir_all(&p)?;
32 Ok(p)
33 }
34
35 pub fn ros_dir(&self) -> io::Result<PathBuf> {
37 let p = self.root_dir.join("ros");
38 fs::create_dir_all(&p)?;
39 Ok(p)
40 }
41
42 pub fn cold_ec_dir(&self) -> io::Result<PathBuf> {
44 let p = self.root_dir.join("cold_ec");
45 fs::create_dir_all(&p)?;
46 Ok(p)
47 }
48
49 pub fn wal_path(&self) -> PathBuf {
51 self.root_dir.join("wal.log")
52 }
53
54 pub fn encrypted_wal_path(&self) -> PathBuf {
56 self.root_dir.join("wal.enc.log")
57 }
58
59 pub fn columnar_cache_dir(&self) -> io::Result<PathBuf> {
61 let p = self.root_dir.join("columnar_cache");
62 fs::create_dir_all(&p)?;
63 Ok(p)
64 }
65
66 pub fn l2_cache_dir(&self) -> io::Result<PathBuf> {
68 let p = self.root_dir.join("l2_cache");
69 fs::create_dir_all(&p)?;
70 Ok(p)
71 }
72
73 pub fn temp_dir(&self) -> io::Result<PathBuf> {
75 let p = self.root_dir.join("tmp");
76 fs::create_dir_all(&p)?;
77 Ok(p)
78 }
79
80 pub fn cleanup_orphans(&self) -> io::Result<()> {
82 let tmp = self.root_dir.join("tmp");
83 if tmp.exists() {
84 info!("Cleaning up orphan temporary files in {:?}", tmp);
85 fs::remove_dir_all(&tmp).ok();
87 fs::create_dir_all(&tmp)?;
88 }
89 Ok(())
90 }
91}