From d329cd08c17b8c7ba47a3dc079f0ab8ebfb23274 Mon Sep 17 00:00:00 2001 From: Ely Date: Mon, 9 Nov 2026 17:20:43 -0500 Subject: [PATCH] Compare the canonical binary path when updating, and report installed symlinks `install_path` canonicalized the installer directory but compared it with `current_exe()` as given. That path is not canonical on every platform (macOS reports the path the binary was started through), so an installer directory reached through a symbolic link refused `proofline update`. On Linux `current_exe()` already names a link's target, so the comparison failed before the symbolic-link check could run, and a package manager's link was reported as "outside the installer directory" instead. Check for the link first, then compare the canonical executable path. --- src/update.rs | 12 ++++++++---- src/update/tests.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/update.rs b/src/update.rs index 76273ab..93c6a4d 100644 --- a/src/update.rs +++ b/src/update.rs @@ -298,15 +298,19 @@ async fn refresh(client: &reqwest::Client, address: &str, path: PathBuf) -> anyh fn install_path(executable: &Path, directory: &Path) -> anyhow::Result { let expected = fs::canonicalize(directory)?.join("proofline"); - if executable != expected { + // Checked first: on Linux `current_exe` already names the link's target, + // so the comparison below would hide why the update is refused. + if fs::symlink_metadata(&expected).is_ok_and(|metadata| metadata.file_type().is_symlink()) { + bail!("the installed binary is a symbolic link; update it through its package manager"); + } + // `current_exe` is not canonical on every platform (macOS reports the path + // the binary was started through), while `expected` is. + if fs::canonicalize(executable).ok().as_deref() != Some(expected.as_path()) { bail!( "this binary is outside the installer directory {}; update it through its package manager or rebuild it from source", directory.display() ); } - if fs::symlink_metadata(&expected)?.file_type().is_symlink() { - bail!("the installed binary is a symbolic link; update it through its package manager"); - } Ok(expected) } diff --git a/src/update/tests.rs b/src/update/tests.rs index 0233c3c..b503e04 100644 --- a/src/update/tests.rs +++ b/src/update/tests.rs @@ -315,3 +315,47 @@ async fn detached_discovery_is_serialized_and_notices_arrive_on_the_next_invocat server.abort(); assert!(server.await.unwrap_err().is_cancelled()); } + +/// `current_exe` is not canonical on every platform (macOS reports the path +/// the binary was started through), so an installer directory reached through +/// a symbolic link is still the installer directory. +#[cfg(unix)] +#[test] +fn installer_directory_reached_through_a_symlink() { + let root = tempfile::tempdir().unwrap(); + let real = root.path().join("real-bin"); + fs::create_dir_all(&real).unwrap(); + fs::write(real.join("proofline"), b"binary").unwrap(); + let linked = root.path().join("linked-bin"); + std::os::unix::fs::symlink(&real, &linked).unwrap(); + + let expected = fs::canonicalize(real.join("proofline")).unwrap(); + assert_eq!( + install_path(&linked.join("proofline"), &linked).unwrap(), + expected + ); + assert_eq!(install_path(&expected, &linked).unwrap(), expected); +} + +/// A package manager's symbolic link in the installer directory is reported +/// as such, whichever path `current_exe` gives for it: the link on macOS, its +/// target on Linux. +#[cfg(unix)] +#[test] +fn installed_symlink_is_reported_as_a_symlink() { + let root = tempfile::tempdir().unwrap(); + let store = root.path().join("store"); + fs::create_dir_all(&store).unwrap(); + fs::write(store.join("proofline"), b"binary").unwrap(); + let bin = root.path().join("bin"); + fs::create_dir_all(&bin).unwrap(); + std::os::unix::fs::symlink(store.join("proofline"), bin.join("proofline")).unwrap(); + + for executable in [ + bin.join("proofline"), + fs::canonicalize(store.join("proofline")).unwrap(), + ] { + let error = install_path(&executable, &bin).unwrap_err().to_string(); + assert!(error.contains("symbolic link"), "{executable:?}: {error}"); + } +}