Skip to content

Commit 60a9237

Browse files
authored
fix(update): refuse to update Homebrew-managed binary (#6)
Detects /Cellar/ or /homebrew/ in current_exe() path and aborts with a message directing user to 'brew upgrade wshm'. Prevents breaking the Cellar structure and Homebrew metadata. Also warns for /usr/bin/ paths which may be managed by apt/dnf/rpm. Same pattern as rtk-ai/icm#105.
1 parent e11dc1c commit 60a9237

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/update.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ fn extract_from_zip(archive_data: &[u8]) -> Result<Vec<u8>> {
230230
fn replace_binary(new_binary: &[u8]) -> Result<PathBuf> {
231231
let current_exe =
232232
std::env::current_exe().context("Cannot determine current executable path")?;
233+
234+
// Detect package-managed installations — refuse to break metadata
235+
let path_str = current_exe.to_string_lossy();
236+
if path_str.contains("/Cellar/") || path_str.contains("/homebrew/") {
237+
anyhow::bail!(
238+
"Detected Homebrew installation ({}).\nUse 'brew upgrade wshm' instead to keep metadata consistent.",
239+
current_exe.display()
240+
);
241+
}
242+
if path_str.starts_with("/usr/bin/") {
243+
warn!(
244+
"{} may be managed by a package manager (apt/dnf/rpm). Consider using your package manager to upgrade.",
245+
current_exe.display()
246+
);
247+
}
248+
233249
let parent = current_exe
234250
.parent()
235251
.context("Cannot determine binary directory")?;

0 commit comments

Comments
 (0)