use crate::snapshot_cache::{SnapshotJsonPaths, SnapshotKey, snapshot_network_dir};
use std::path::{Path, PathBuf};
pub(in crate::sns::report) trait SnsCacheCollection {
const COLLECTION: &'static str;
}
pub(in crate::sns::report) fn sns_snapshot_cache_paths<Collection>(
cache_root: &Path,
network: &str,
root_canister_id: &str,
) -> SnapshotJsonPaths
where
Collection: SnsCacheCollection,
{
let snapshot_key = SnapshotKey::full("sns", network, root_canister_id, Collection::COLLECTION);
SnapshotJsonPaths::for_key(cache_root, &snapshot_key)
}
pub(in crate::sns::report) fn sns_snapshot_network_cache_dir(
cache_root: &Path,
network: &str,
) -> PathBuf {
snapshot_network_dir(cache_root, "sns", network)
}
pub(in crate::sns::report) fn sns_attempt_path_for_cache_path(cache_path: &Path) -> PathBuf {
cache_path.with_file_name("full.refresh-attempt.json")
}
pub(in crate::sns::report) fn sns_snapshot_key_for_cache_path<Collection>(
network: &str,
cache_path: &Path,
) -> SnapshotKey
where
Collection: SnsCacheCollection,
{
let entity = cache_path
.parent()
.and_then(Path::parent)
.and_then(Path::file_name)
.and_then(|name| name.to_str())
.unwrap_or_default();
SnapshotKey::full("sns", network, entity, Collection::COLLECTION)
}