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)
| 770 | /// deadline so a wedged binary cannot hang the upgrade. `None` when it |
| 771 | /// cannot be run, times out, or its output is unrecognizable. |
| 772 | fn 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 |
nothing calls this directly
no test coverage detected