fn self_update_check_inner() -> eyre::Result<bool> {
    let client = ureq::builder()
        .redirects(0)
        .timeout(std::time::Duration::from_secs(1))
        .build();

    let url = [LATEST_URL, LATEST_ZIP_PATH].concat();
    let res = client.get(&url).call()?;
    let latest_url = res
        .header("location")
        .ok_or_else(|| eyre!("no location header in update check response"))?;

    // ensure containing direction of cache file exists
    fs::create_dir_all(cache_dir())?;

    let update_check_cache_path = cache_dir().join(UPDATE_CHECK_FILENAME);
    let mut file = fs::File::create(&update_check_cache_path)?;

    // for some download URL like:
    // update-server.com/release/v1.2.3/download
    // it should only be required that the current version exists somewhere in that URL
    // to be considered the latest to avoid needing regex and oddities with v* prefixes
    let update_needed = !latest_url.contains(SELF_VERSION);

    let last_check = UpdateCheck {
        update_needed,
        checked_with: SELF_VERSION.to_owned(),
        last_check: time::OffsetDateTime::now_utc(),
    };

    let update_check = serde_json::to_vec_pretty(&last_check)?;
    // TODO: less resilient than other file ops
    file.write_all(&update_check)?;

    eprintln!("checking cache at {:?}", &update_check_cache_path);

    Ok(update_needed)
}
// Makes API call to GitHub to check latest
Makes API call to GitHub to check latest
Makes API call to GitHub to check latest
fn self_update_check_inner() -> eyre::Result<bool> {
    let client = ureq::builder()
        .redirects(0)
        .timeout(std::time::Duration::from_secs(1))
        .build();
    let url = [LATEST_URL, LATEST_ZIP_PATH].concat();
    let res = client.get(&url).call()?;
    let latest_url = res
        .header("location")
        .ok_or_else(|| eyre!("no location header in update check response"))?;
    // ensure containing direction of cache file exists
    fs::create_dir_all(cache_dir())?;
    let update_check_cache_path = cache_dir().join(UPDATE_CHECK_FILENAME);
    let mut file = fs::File::create(&update_check_cache_path)?;
    // for some download URL like:
    // update-server.com/release/v1.2.3/download
    // it should only be required that the current version exists somewhere in that URL
    // to be considered the latest to avoid needing regex and oddities with v* prefixes
    let update_needed = !latest_url.contains(SELF_VERSION);
    let last_check = UpdateCheck {
        update_needed,
        checked_with: SELF_VERSION.to_owned(),
        last_check: time::OffsetDateTime::now_utc(),
    };
    let update_check = serde_json::to_vec_pretty(&last_check)?;
    // TODO: less resilient than other file ops
    file.write_all(&update_check)?;
    eprintln!("checking cache at {:?}", &update_check_cache_path);
    Ok(update_needed)
}
fn self_update_check_inner ( ) -> eyre :: Result < bool > { let client = ureq :: builder ( ) . redirects ( 0 ) . timeout ( std :: time :: Duration :: from_secs ( 1 ) ) . build ( ) ; let url = [ LATEST_URL , LATEST_ZIP_PATH ] . concat ( ) ; let res = client . get ( & url ) . call ( ) ? ; let latest_url = res . header ( " " ) . ok_or_else ( | | eyre ! ( " " ) ) ? ; // ensure containing direction of cache file exists fs :: create_dir_all ( cache_dir ( ) ) ? ; let update_check_cache_path = cache_dir ( ) . join ( UPDATE_CHECK_FILENAME ) ; let mut file = fs :: File :: create ( & update_check_cache_path ) ? ; // for some download URL like: // update-server.com/release/v1.2.3/download // it should only be required that the current version exists somewhere in that URL // to be considered the latest to avoid needing regex and oddities with v* prefixes let update_needed = ! latest_url . contains ( SELF_VERSION ) ; let last_check = UpdateCheck { update_needed , checked_with : SELF_VERSION . to_owned ( ) , last_check : time :: OffsetDateTime :: now_utc ( ) , } ; let update_check = serde_json :: to_vec_pretty ( & last_check ) ? ; // TODO: less resilient than other file ops file . write_all ( & update_check ) ? ; eprintln ! ( " " update_check_cache_path ) ; Ok ( update_needed ) }
Makes API call to GitHub to check latest
Makes API call to GitHub to check latest