From 08193537dad04d764ec14902c5a8f9155dc4d276 Mon Sep 17 00:00:00 2001 From: dandels Date: Thu, 19 Dec 2024 13:22:40 +0200 Subject: [PATCH] Misc code cleanup --- src/api/update_status.rs | 12 +----------- src/cache/mod.rs | 10 ++-------- src/cache/modfile_metadata.rs | 1 + 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/api/update_status.rs b/src/api/update_status.rs index cb760eb..1bf23a1 100644 --- a/src/api/update_status.rs +++ b/src/api/update_status.rs @@ -23,16 +23,6 @@ impl Default for UpdateStatus { } } -impl UpdateStatus { - pub fn time(&self) -> u64 { - match self { - Self::UpToDate(t) | Self::HasNewFile(t) | Self::OutOfDate(t) | Self::IgnoredUntil(t) | Self::Invalid(t) => { - *t - } - } - } -} - // Hack to retain backward compatibility with previously serialized data and provide a better API than two atomics #[derive(Clone, Debug)] pub struct UpdateStatusWrapper { @@ -71,7 +61,7 @@ impl UpdateStatusWrapper { } pub fn sync_with(&self, other: &Self) { - if self.time.load(Ordering::Relaxed) < other.time.load(Ordering::Relaxed) { + if self.time() < other.time() { self.set(other.to_enum()); } else { other.set(self.to_enum()); diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 82be2f6..33baa47 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -178,21 +178,15 @@ impl Cache { let mut file = File::create(path).await?; file.write_all(format!("{}", time).as_bytes()).await } - - // Loads timestamp from $XDG_CACHE_DIR/dmodman/$profile/last_updated - pub fn load_last_updated(&self, config: &Config) -> Arc { - let val = try_read_last_updated(config); - self.last_update_check.store(val, Ordering::Relaxed); - Arc::new(AtomicU64::new(val)) - } } +// Loads timestamp from $XDG_CACHE_DIR/dmodman/$profile/last_updated fn try_read_last_updated(config: &Config) -> u64 { let mut path = config.cache_for_profile(); path.push("last_updated"); match std::fs::read_to_string(path) { Ok(contents) => contents.parse::().unwrap_or_default(), - Err(_) => 0 + Err(_) => 0, } } diff --git a/src/cache/modfile_metadata.rs b/src/cache/modfile_metadata.rs index 89409b8..45ab38d 100644 --- a/src/cache/modfile_metadata.rs +++ b/src/cache/modfile_metadata.rs @@ -80,6 +80,7 @@ impl ModFileMetadata { self.file_details.read().await.as_ref().map(|fd| fd.name.clone()) } + #[allow(dead_code)] pub async fn mod_info(&self) -> Option> { self.mod_info.read().await.clone() }