Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dre): Only check for updates once per day #548

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rs/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,16 @@ fn init_logger() {
}

fn check_latest_release(curr_version: &str, proceed_with_upgrade: bool) -> anyhow::Result<UpdateStatus> {
// Check for a new release once per day
let update_check_path = dirs::cache_dir().expect("Failed to find a cache dir").join("dre_update_check");
if let Ok(metadata) = std::fs::metadata(&update_check_path) {
let last_check = metadata.modified().unwrap();
let now = std::time::SystemTime::now();
if now.duration_since(last_check).unwrap().as_secs() < 60 * 60 * 24 {
return Ok(UpdateStatus::NoUpdate);
}
}

// ^ --> start of line
// v? --> optional 'v' char
// (\d+\.\d+\.\d+) --> string in format '1.22.33'
Expand All @@ -669,6 +679,9 @@ fn check_latest_release(curr_version: &str, proceed_with_upgrade: bool) -> anyho
.build()
.map_err(|e| anyhow::anyhow!("Configuring backend failed: {:?}", e))?;

// Touch update check file
std::fs::write(&update_check_path, "").map_err(|e| anyhow::anyhow!("Couldn't touch update check file: {:?}", e))?;

let releases = maybe_configured_backend
.fetch()
.map_err(|e| anyhow::anyhow!("Fetching releases failed: {:?}", e))?;
Expand Down
Loading