Files
ruvnet--RuView/v2/crates/wifi-densepose-geo/src/cache.rs
T
rUv f49c722764 chore(repo): rename rust-port/wifi-densepose-rs → v2/ (flatten to one level) (#427)
The Rust port lived two directories deep (rust-port/wifi-densepose-rs/)
without any sibling under rust-port/ that warranted the extra level.
Move the whole workspace up to v2/ to match v1/ (Python) at the same
depth and shorten every cd / build command across the repo.

git mv preserves history for all tracked files. 60 files updated for
path references (CI workflows, ADRs, docs, scripts, READMEs, internal
.claude-flow state). Two manual fixes for relative-cd paths in
CLAUDE.md and ADR-043 that became wrong after the depth change
(cd ../.. → cd ..).

Validated:
- cargo check --workspace --no-default-features → clean (after target/
  nuke; the gitignored target/ was carried by the OS rename and had
  hard-coded old paths in build scripts)
- cargo test --workspace --no-default-features → 1,539 passed, 0 failed,
  8 ignored (same totals as pre-rename)
- ESP32-S3 on COM7 → still streaming live CSI (cb #40300, RSSI -64 dBm)

After-merge follow-up: contributors should `rm -rf v2/target` once and
let cargo regenerate from the new path.
2026-04-25 21:28:13 -04:00

62 lines
1.6 KiB
Rust

//! Disk cache for tiles, DEM, and OSM data.
use anyhow::Result;
use std::path::{Path, PathBuf};
pub struct TileCache {
pub base_dir: PathBuf,
}
impl TileCache {
pub fn new(base_dir: &str) -> Self {
let expanded = base_dir.replace('~', &std::env::var("HOME").unwrap_or_default());
let path = PathBuf::from(expanded);
let _ = std::fs::create_dir_all(&path);
Self { base_dir: path }
}
pub fn default_cache() -> Self {
Self::new("~/.local/share/ruview/geo-cache")
}
pub fn get(&self, key: &str) -> Option<Vec<u8>> {
let path = self.key_path(key);
std::fs::read(&path).ok()
}
pub fn put(&self, key: &str, data: &[u8]) -> Result<()> {
let path = self.key_path(key);
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}
std::fs::write(&path, data)?;
Ok(())
}
pub fn has(&self, key: &str) -> bool {
self.key_path(key).exists()
}
pub fn size_bytes(&self) -> u64 {
walkdir(self.base_dir.as_path())
}
fn key_path(&self, key: &str) -> PathBuf {
// Sanitize key to prevent path traversal
let safe_key = key.replace("..", "_").replace('/', "_");
self.base_dir.join(safe_key)
}
}
fn walkdir(path: &Path) -> u64 {
std::fs::read_dir(path)
.into_iter()
.flatten()
.filter_map(|e| e.ok())
.map(|e| {
if e.path().is_dir() { walkdir(&e.path()) }
else { e.metadata().map(|m| m.len()).unwrap_or(0) }
})
.sum()
}