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
GETthe crate’s index file athttps://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
ETagback asIf-None-Match, so an unchanged index answers304 Not Modifiedwith no body — the cheap path the CDN is built for. - Throttled. At most one network poll per interval (daily by default,
CT_UPDATE_CHECKoverrides), recorded in a small state file under the user’s cache directory. - Never blocking. The foreground
ctinvocation 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. Actcommand 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.patchcore 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
ctflag 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 under3/<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
latestis a strictly newer release thancurrent. 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;Nonemeans nothing usable was found. - on_
invocation - Called once per real
ctinvocation. 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_CHECKvalue into a poll interval in seconds, orNoneto 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.