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

Function installed_binary_version

src/upgrade.rs:772–798  ·  view source on GitHub ↗

Asks the binary at `path` for its version, killing it after a short deadline so a wedged binary cannot hang the upgrade. `None` when it cannot be run, times out, or its output is unrecognizable.

(path: &Path)

Source from the content-addressed store, hash-verified

770/// deadline so a wedged binary cannot hang the upgrade. `None` when it
771/// cannot be run, times out, or its output is unrecognizable.
772fn installed_binary_version(path: &Path) -> Option<String> {
773 let mut child = std::process::Command::new(path)
774 .arg("--version")
775 .stdout(Stdio::piped())
776 .stderr(Stdio::null())
777 .spawn()
778 .ok()?;
779 let deadline = Instant::now() + Duration::from_secs(5);
780 let status = loop {
781 match child.try_wait() {
782 Ok(Some(status)) => break status,
783 Ok(None) if Instant::now() >= deadline => {
784 let _ = child.kill();
785 let _ = child.wait();
786 return None;
787 }
788 Ok(None) => std::thread::sleep(Duration::from_millis(50)),
789 Err(_) => return None,
790 }
791 };
792 if !status.success() {
793 return None;
794 }
795 let mut output = String::new();
796 child.stdout.take()?.read_to_string(&mut output).ok()?;
797 parse_version_output(&output)
798}
799
800/// Whether a delegated `brew upgrade` was a no-op: the linked binary still
801/// reports the version we are already running. `None` (undetectable) is

Callers

nothing calls this directly

Calls 4

parse_version_outputFunction · 0.85
successMethod · 0.80
spawnMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected