Skip to content

Commit

Permalink
chore: don't message if Rover is already up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Mar 17, 2021
1 parent 9f5749c commit 5c04dac
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/utils/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const ONE_DAY: u64 = ONE_HOUR * 24;

/// check for newer versions of rover.
///
/// If this fn is run explicitly from a user-facing command, we pass `force` to
/// If this fn is run explicitly from a user-facing command, we pass `is_foreground` to
/// check for newer versions, even if we recently checked for updates.
///
/// If `force` is not passed, we check for updates every day at most
pub fn check_for_update(config: config::Config, force: bool) -> Result<()> {
/// If `is_foreground` is not passed, we check for updates every day at most
pub fn check_for_update(config: config::Config, is_foreground: bool) -> Result<()> {
let version_file = config.home.join("version.toml");
let current_time = SystemTime::now();
// if we don't end up checking, we don't want to overwrite the last checked time
Expand All @@ -27,25 +27,19 @@ pub fn check_for_update(config: config::Config, force: bool) -> Result<()> {
// check fs for last check time
let last_checked_time = get_last_checked_time_from_disk(&version_file);

match last_checked_time {
Some(last_checked_time) => {
let time_since_check = current_time.duration_since(last_checked_time)?.as_secs();
tracing::debug!(
"Time since last update check: {:?}h",
time_since_check / ONE_HOUR
);
if is_foreground || last_checked_time.is_none() {
do_update_check(&mut checked, is_foreground)?;
} else if let Some(last_checked_time) = last_checked_time {
let time_since_check = current_time.duration_since(last_checked_time)?.as_secs();
tracing::debug!(
"Time since last update check: {:?}h",
time_since_check / ONE_HOUR
);

if force || time_since_check > ONE_DAY {
do_update_check(&mut checked)?;
} else {
tracing::debug!(
"No need to check for updates. Automatic checks happen once per day"
);
}
}
// we haven't checked for updates before -- check now :)
None => {
do_update_check(&mut checked)?;
if time_since_check > ONE_DAY {
do_update_check(&mut checked, is_foreground)?;
} else {
tracing::debug!("No need to check for updates. Automatic checks happen once per day");
}
}

Expand All @@ -57,7 +51,7 @@ pub fn check_for_update(config: config::Config, force: bool) -> Result<()> {
Ok(())
}

fn do_update_check(checked: &mut bool) -> Result<()> {
fn do_update_check(checked: &mut bool, should_output_if_updated: bool) -> Result<()> {
let latest = get_latest_release()?;
let update_available = is_latest_newer(&latest, PKG_VERSION)?;

Expand All @@ -72,7 +66,7 @@ fn do_update_check(checked: &mut bool) -> Result<()> {
.box_alignment(Alignment::Left)
.build()
.eprint(message);
} else {
} else if should_output_if_updated {
eprintln!("Rover is up to date!");
}

Expand Down

0 comments on commit 5c04dac

Please sign in to comment.