use std::path::PathBuf;
use std::time::SystemTime;
use bon::bon;
use crate::client::HFClient;
use crate::error::HFResult;
pub(crate) mod storage;
#[derive(Debug, Clone)]
pub struct CachedFileInfo {
pub file_name: String,
pub file_path: PathBuf,
pub blob_path: PathBuf,
pub size_on_disk: u64,
pub blob_last_accessed: SystemTime,
pub blob_last_modified: SystemTime,
}
#[derive(Debug, Clone)]
pub struct CachedRevisionInfo {
pub commit_hash: String,
pub snapshot_path: PathBuf,
pub files: Vec<CachedFileInfo>,
pub size_on_disk: u64,
pub refs: Vec<String>,
pub last_modified: SystemTime,
}
#[derive(Debug, Clone)]
pub struct CachedRepoInfo {
pub repo_id: String,
pub repo_type: &'static str,
pub repo_path: PathBuf,
pub revisions: Vec<CachedRevisionInfo>,
pub nb_files: usize,
pub size_on_disk: u64,
pub last_accessed: SystemTime,
pub last_modified: SystemTime,
}
#[derive(Debug, Clone)]
pub struct HFCacheInfo {
pub cache_dir: PathBuf,
pub repos: Vec<CachedRepoInfo>,
pub size_on_disk: u64,
pub warnings: Vec<String>,
}
#[bon]
impl HFClient {
#[builder(finish_fn = send, derive(Debug, Clone))]
pub async fn scan_cache(&self) -> HFResult<HFCacheInfo> {
storage::scan_cache_dir(self.cache_dir()).await
}
}
#[cfg(feature = "blocking")]
#[bon]
impl crate::blocking::HFClientSync {
#[builder(finish_fn = send, derive(Debug, Clone))]
pub fn scan_cache(&self) -> HFResult<HFCacheInfo> {
self.runtime.block_on(self.inner.scan_cache().send())
}
}