Skip to main content

smugmug_cli/cache/
mod.rs

1use anyhow::{Context, Result};
2use directories::ProjectDirs;
3use std::path::PathBuf;
4
5pub mod hash_store;
6
7pub use hash_store::HashStore;
8
9/// Get the default cache directory path
10pub fn get_cache_path() -> Result<PathBuf> {
11    let project_dirs = ProjectDirs::from("com", "jhofker", "smugmug-cli")
12        .context("Failed to determine project directories")?;
13
14    let cache_dir = project_dirs.cache_dir().join("hash_store");
15
16    // Ensure the cache directory exists
17    std::fs::create_dir_all(&cache_dir).context("Failed to create cache directory")?;
18
19    Ok(cache_dir)
20}
21
22/// Clear the deduplication cache
23pub fn clear_cache() -> Result<()> {
24    let cache_path = get_cache_path()?;
25    let store = HashStore::new(cache_path.to_str().unwrap())?;
26
27    let stats = store.stats()?;
28    println!("Clearing {} entries from cache...", stats.total_entries);
29
30    store.clear()?;
31    println!("Cache cleared successfully!");
32
33    Ok(())
34}