MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / check_for_update

Function check_for_update

src/global.rs:269–311  ·  view source on GitHub ↗

Best-effort version check with 5-minute network cache. If `skip_cache` is true, always fetches from GitHub (used during sync where the call runs in parallel). If `skip_suppression` is false, the warning is suppressed for 15 minutes after it was last shown; if true it is always shown (used for status).

(
    config: &mut tracedecay::user_config::UserConfig,
    skip_cache: bool,
    skip_suppression: bool,
)

Source from the content-addressed store, hash-verified

267/// parallel). If `skip_suppression` is false, the warning is suppressed for 15
268/// minutes after it was last shown; if true it is always shown (used for status).
269pub(crate) fn check_for_update(
270 config: &mut tracedecay::user_config::UserConfig,
271 skip_cache: bool,
272 skip_suppression: bool,
273) {
274 let current_version = env!("CARGO_PKG_VERSION");
275 let now = current_unix_timestamp();
276
277 let latest = if !skip_cache && elapsed_since(now, config.last_version_check_at) < 300 {
278 // Use cached value
279 if config.cached_latest_version.is_empty() {
280 return;
281 }
282 config.cached_latest_version.clone()
283 } else if let Some(v) = tracedecay::cloud::fetch_latest_version() {
284 config.cached_latest_version = v.clone();
285 config.last_version_check_at = now;
286 config.save_if_exists();
287 v
288 } else {
289 return;
290 };
291
292 // The status page (skip_suppression=true) warns on any newer version;
293 // the CLI only warns on minor+ bumps to avoid nagging on patch releases.
294 let dominated = if skip_suppression {
295 tracedecay::cloud::is_newer_version(current_version, &latest)
296 } else {
297 tracedecay::cloud::is_newer_minor_version(current_version, &latest)
298 };
299
300 if dominated && (skip_suppression || elapsed_since(now, config.last_version_warning_at) >= 900)
301 {
302 eprintln!(
303 "\n\x1b[33mUpdate available: v{} → v{}\x1b[0m\n Run: \x1b[1mtracedecay upgrade\x1b[0m",
304 current_version, latest
305 );
306 if !skip_suppression {
307 config.last_version_warning_at = now;
308 config.save_if_exists();
309 }
310 }
311}
312
313/// Returns the total size in bytes of every file under `dir`. Best-effort.
314pub(crate) fn tracedecay_dir_size(dir: &Path) -> u64 {

Callers 1

handle_status_commandFunction · 0.85

Calls 7

current_unix_timestampFunction · 0.85
elapsed_sinceFunction · 0.85
is_newer_versionFunction · 0.85
is_newer_minor_versionFunction · 0.85
save_if_existsMethod · 0.80
fetch_latest_versionFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected