Skip to content

Commit

Permalink
Misc code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dandels committed Dec 19, 2024
1 parent bc342e8 commit 0819353
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
12 changes: 1 addition & 11 deletions src/api/update_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down
10 changes: 2 additions & 8 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AtomicU64> {
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::<u64>().unwrap_or_default(),
Err(_) => 0
Err(_) => 0,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/cache/modfile_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<ModInfo>> {
self.mod_info.read().await.clone()
}
Expand Down

0 comments on commit 0819353

Please sign in to comment.