Add the cast-allow block to zesdex-entities/src/lib.rs and zesdex-utils/src/lib.rs (which lacked it), then remove from 65 sub-files across all 8 crates. Build and all 223 tests continue to pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
58 lines
2.0 KiB
Rust
58 lines
2.0 KiB
Rust
//! Filesystem layout for zesdex's persistent and scratch data directories.
|
|
use serde::{Deserialize, Serialize};
|
|
use std::path::PathBuf;
|
|
|
|
/// Resolved paths for all data directories zesdex reads from and writes to.
|
|
///
|
|
/// Why: centralizing path computation here means every consumer agrees on
|
|
/// where memory, scratch, session images, and downloads live.
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Store {
|
|
pub base_dir: PathBuf,
|
|
pub scratch_root: PathBuf,
|
|
pub memory_dir: PathBuf,
|
|
pub session_images_dir: PathBuf,
|
|
pub download_dir: PathBuf,
|
|
}
|
|
|
|
impl Store {
|
|
/// Compute the standard set of zesdex data directory paths.
|
|
///
|
|
/// Flow: OS data dir (or `.local/share` fallback) + "zesdex" → base dir;
|
|
/// scratch root comes from the OS temp dir instead, since it's disposable.
|
|
///
|
|
/// Why: paths are computed, not created — call `ensure_dirs` before use.
|
|
pub fn new() -> Self {
|
|
let base = dirs::data_dir()
|
|
.unwrap_or_else(|| PathBuf::from(".local/share"))
|
|
.join("zesdex");
|
|
let scratch = std::env::temp_dir().join("zesdex-scratch");
|
|
Store {
|
|
memory_dir: base.join("memory"),
|
|
scratch_root: scratch,
|
|
session_images_dir: base.join("session-images"),
|
|
download_dir: base.join("downloads"),
|
|
base_dir: base,
|
|
}
|
|
}
|
|
|
|
/// Create all store directories (base, memory, scratch, session images,
|
|
/// downloads) if missing.
|
|
///
|
|
/// Return: `Err` on the first directory that fails to create.
|
|
pub fn ensure_dirs(&self) -> std::io::Result<()> {
|
|
std::fs::create_dir_all(&self.base_dir)?;
|
|
std::fs::create_dir_all(&self.memory_dir)?;
|
|
std::fs::create_dir_all(&self.scratch_root)?;
|
|
std::fs::create_dir_all(&self.session_images_dir)?;
|
|
std::fs::create_dir_all(&self.download_dir)?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl Default for Store {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|