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,
)
| 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). |
| 269 | pub(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. |
| 314 | pub(crate) fn tracedecay_dir_size(dir: &Path) -> u64 { |
no test coverage detected