use std::path::{Path, PathBuf};
pub fn snapshot_file(i: usize) -> String {
format!("dump-{i}.rdb")
}
pub fn aof_file(i: usize) -> String {
format!("aof-{i}.aof")
}
pub fn snapshot_path(dir: &Path, i: usize) -> PathBuf {
dir.join(snapshot_file(i))
}
pub fn aof_path(dir: &Path, i: usize) -> PathBuf {
dir.join(aof_file(i))
}
pub fn shards_meta_path(dir: &Path) -> PathBuf {
dir.join("shards.meta")
}
pub fn infer_files_n(dir: &Path) -> usize {
let mut n = 0usize;
let Ok(entries) = std::fs::read_dir(dir) else {
return 0;
};
for entry in entries.flatten() {
let name = entry.file_name();
let Some(name) = name.to_str() else { continue };
let idx = name
.strip_prefix("dump-")
.and_then(|r| r.strip_suffix(".rdb"))
.or_else(|| name.strip_prefix("aof-").and_then(|r| r.strip_suffix(".aof")));
if let Some(i) = idx.and_then(|s| s.parse::<usize>().ok()) {
n = n.max(i + 1);
}
}
n
}