Skip to content

Commit 7b743fb

Browse files
committed
reading cache directory during runtime without dir crate
1 parent e774e7e commit 7b743fb

File tree

5 files changed

+43
-152
lines changed

5 files changed

+43
-152
lines changed

Cargo.lock

Lines changed: 4 additions & 145 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ arkworks = [
4747
]
4848
parallel = ["dep:rayon", "ark-ec?/parallel", "ark-ff?/parallel"]
4949
cache = ["arkworks", "dep:once_cell", "parallel"]
50-
disk-persistence = ["dep:dirs"]
50+
disk-persistence = []
5151

5252
[dependencies]
5353
thiserror = "2.0"
5454
rand_core = "0.6"
5555
dory-derive = { version = "0.1.0", path = "derive" }
5656
tracing = "0.1"
57-
dirs = { version = "5.0", optional = true }
5857

5958
# Arkworks backend
6059
ark-bn254 = { version = "0.5.0", optional = true }

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ pub use proof::DoryProof;
110110
pub use reduce_and_fold::{DoryProverState, DoryVerifierState};
111111
pub use setup::{ProverSetup, VerifierSetup};
112112

113+
#[cfg(feature = "disk-persistence")]
114+
pub use setup::get_storage_dir;
115+
113116
/// Generate or load prover and verifier setups from disk
114117
///
115118
/// Creates or loads the transparent setup parameters for Dory PCS.

src/setup.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,41 @@ impl<E: PairingCurve> ProverSetup<E> {
204204
/// - Windows: `{FOLDERID_LocalAppData}\dory\`
205205
///
206206
/// Note: Uses XDG cache directory for persistent storage.
207+
/// Detects OS at runtime by checking environment variables, then determines the cache directory.
207208
#[cfg(feature = "disk-persistence")]
208-
fn get_storage_dir() -> Option<PathBuf> {
209-
dirs::cache_dir().map(|mut path| {
209+
pub fn get_storage_dir() -> Option<PathBuf> {
210+
// Check for Windows first (LOCALAPPDATA is Windows-specific)
211+
if let Ok(local_app_data) = std::env::var("LOCALAPPDATA") {
212+
let mut path = PathBuf::from(local_app_data);
210213
path.push("dory");
211-
path
212-
})
214+
return Some(path);
215+
}
216+
217+
// For Unix-like systems, check for HOME
218+
if let Ok(home) = std::env::var("HOME") {
219+
let mut path = PathBuf::from(&home);
220+
221+
// Check if Library/Caches exists (macOS indicator)
222+
let macos_cache = {
223+
let mut test_path = PathBuf::from(&home);
224+
test_path.push("Library");
225+
test_path.push("Caches");
226+
test_path.exists()
227+
};
228+
229+
if macos_cache {
230+
path.push("Library");
231+
path.push("Caches");
232+
} else {
233+
// Linux and other Unix-like systems
234+
path.push(".cache");
235+
}
236+
237+
path.push("dory");
238+
return Some(path);
239+
}
240+
241+
None
213242
}
214243

215244
/// Get the full path to the setup file for a given max_log_n

tests/arkworks/setup.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,13 @@ fn test_arkworks_setup_new_from_urs() {
151151
use dory_pcs::backends::arkworks::ArkworksProverSetup;
152152
use dory_pcs::{backends::arkworks::BN254, generate_urs};
153153
use rand::thread_rng;
154+
use dory_pcs::setup::get_storage_dir;
154155

155156
let mut rng = thread_rng();
156157
let max_log_n = 14;
157158

158159
// Clean up any existing cache file first
159-
if let Some(cache_dir) = dirs::cache_dir() {
160+
if let Some(cache_dir) = get_storage_dir() {
160161
let cache_file = cache_dir
161162
.join("dory")
162163
.join(format!("dory_{}.urs", max_log_n));

0 commit comments

Comments
 (0)