use std::path::Path;
use super::{DownloadError, hf};
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Freshness {
Unknown,
Current,
Stale {
local: String,
remote: String,
},
Missing,
}
impl Freshness {
pub fn is_stale(&self) -> bool {
matches!(self, Self::Stale { .. })
}
}
pub fn check(repo: &str, cache_root: &Path) -> Result<Freshness, DownloadError> {
let Some(local) = hf::local_revision(cache_root, repo) else {
return Ok(Freshness::Missing);
};
let (remote, _) = hf::repo_info(repo, hf::token().as_deref())?;
Ok(if local == remote {
Freshness::Current
} else {
Freshness::Stale { local, remote }
})
}
pub fn short(revision: &str) -> String {
revision.chars().take(7).collect()
}
#[cfg(test)]
#[path = "stale_tests.rs"]
mod tests;