Skip to main content

Module update

Module update 

Source
Expand description

Best-effort “is there a newer release?” check against the crates.io sparse index, wired into the ct umbrella so the suite can tell you when an update is available without ever getting in your way.

The design follows the crates.io guidance for polite, CDN-friendly polling:

  • Sparse protocol over the CDN. We GET the crate’s index file at https://index.crates.io/<path> (the same host cargo’s sparse registry uses, fronted by a CDN), rather than cloning the git index. The path is built from the crate name by cargo’s rule (index_path).
  • Conditional requests. We send the previous response’s ETag back as If-None-Match, so an unchanged index answers 304 Not Modified with no body — the cheap path the CDN is built for.
  • Throttled. At most one network poll per interval (daily by default, CT_UPDATE_CHECK overrides), recorded in a small state file under the user’s cache directory.
  • Never blocking. The foreground ct invocation only reads that cached state (on_invocation); the actual network poll runs in a detached background process (run_background_poll) that writes the state for a later run to notice. A ct command never waits on the network.

Everything here is best-effort: any error — no network, a malformed index, an unwritable cache — is swallowed silently. An update check must never fail a command or print a diagnostic of its own.

Structs§

Version
A minimal semantic version: the major.minor.patch core plus a pre-release marker. Build metadata is ignored; pre-release identifiers compare as a lexical fallback, which is ample for “is there a newer release than mine?”.

Constants§

BG_FLAG
The hidden ct flag that runs the background network poll.

Functions§

index_path
The crates.io sparse-index path for a crate name, by cargo’s rule: 1- and 2-char names live under 1//2/, 3-char under 3/<first>/, and everything else under <first-two>/<next-two>/. The name is lower-cased.
index_url
The full sparse-index URL for a crate.
is_newer
Whether latest is a strictly newer release than current. Unparsable versions compare as “not newer” — we never nag on garbage.
latest_from_index
The highest non-yanked version in a sparse-index document (one JSON object per line). Lines that don’t parse, lack a vers, or are yanked are skipped; None means nothing usable was found.
on_invocation
Called once per real ct invocation. Reads the cached state, prints the first-run and “update available” notices when due (only to a terminal, so scripts and pipes stay clean), and — if a poll is due — claims the slot and spawns the detached background poll. Does no network I/O itself. Silent and infallible: any problem is swallowed.
parse_interval
Parse a CT_UPDATE_CHECK value into a poll interval in seconds, or None to disable the check entirely.
run_background_poll
The entry point for ct --update-check-run: perform one conditional GET against the sparse index and update the cached state. Silent and infallible.