Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(cli-install): recognize Cap-managed shims with canonical path comparison

Richie McIlroy242ec42484e9
diff --git a/crates/cli-install/src/lib.rs b/crates/cli-install/src/lib.rs
index 14f2d8ee4..fb2dd5406 100644
--- a/crates/cli-install/src/lib.rs
+++ b/crates/cli-install/src/lib.rs
@@ -102,12 +102,32 @@ fn path_contains_install_dir(install_dir: &Path) -> bool {
#[cfg(unix)]
fn shim_points_to(shim_path: &Path, target_path: &Path) -> Result<bool, String> {
match fs::read_link(shim_path) {
- Ok(link) => Ok(link == target_path),
- Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(false),
+ // The web installer may symlink to a literal app path that the desktop's canonicalized
+ // current_exe spells differently; compare the resolved paths too so a Cap-managed shim is still
+ // recognized by status/install/uninstall.
+ Ok(link) => Ok(link == target_path || same_file(&link, target_path)),
+ // A non-symlink regular file (read_link → InvalidInput) or a missing path is simply not a
+ // Cap-managed shim — let the caller report that as a conflict rather than surfacing a raw error.
+ Err(err)
+ if matches!(
+ err.kind(),
+ std::io::ErrorKind::NotFound | std::io::ErrorKind::InvalidInput
+ ) =>
+ {
+ Ok(false)
+ }
Err(err) => Err(format!("Could not read CLI shim: {err}")),
}
}
+#[cfg(unix)]
+fn same_file(a: &Path, b: &Path) -> bool {
+ match (fs::canonicalize(a), fs::canonicalize(b)) {
+ (Ok(a), Ok(b)) => a == b,
+ _ => false,
+ }
+}
+
#[cfg(windows)]
fn shim_points_to(shim_path: &Path, target_path: &Path) -> Result<bool, String> {
let contents = match fs::read_to_string(shim_path) {