diff --git a/crates/squid-core/src/error.rs b/crates/squid-core/src/error.rs index de5c4c3..1528c01 100644 --- a/crates/squid-core/src/error.rs +++ b/crates/squid-core/src/error.rs @@ -5,6 +5,16 @@ use std::path::PathBuf; pub type Result = std::result::Result; +/// How a user gains administrator rights on this platform. Keeps the +/// "needs admin" hints truthful on Windows, where there is no sudo. +pub fn elevation_hint() -> &'static str { + if cfg!(windows) { + "run squid from an elevated (Administrator) terminal" + } else { + "run squid with sudo" + } +} + #[derive(Debug, thiserror::Error)] pub enum SquidError { #[error("io error while accessing {path}: {source}")] @@ -29,9 +39,11 @@ pub enum SquidError { what: &'static str, }, - #[error( - "permission denied for {path} — grant Full Disk Access to squid, or run again with sudo" - )] + #[error("permission denied for {path} — {}", if cfg!(windows) { + "run squid from an elevated (Administrator) terminal" + } else { + "grant Full Disk Access to squid, or run again with sudo" + })] Permission { path: PathBuf }, #[error("{0}")] diff --git a/crates/squid-core/src/lib.rs b/crates/squid-core/src/lib.rs index 11210f4..8c5ab08 100644 --- a/crates/squid-core/src/lib.rs +++ b/crates/squid-core/src/lib.rs @@ -16,7 +16,7 @@ pub mod safety; pub mod settings; pub use bytes::Bytes; -pub use error::{Result, SquidError}; +pub use error::{elevation_hint, Result, SquidError}; pub use model::{ AppInfo, Category, CleanSummary, CleanupItem, DeleteMode, ItemKind, LockReason, ScanReport, UninstallPlan, Volume, diff --git a/crates/squid-core/src/safety.rs b/crates/squid-core/src/safety.rs index c1e0725..c49677d 100644 --- a/crates/squid-core/src/safety.rs +++ b/crates/squid-core/src/safety.rs @@ -312,7 +312,10 @@ impl SafetyPolicy { { return Err(SquidError::safety( path, - "outside the current user's home (use sudo to clean system paths)", + format!( + "outside the current user's home ({} to clean system paths)", + crate::elevation_hint() + ), )); } diff --git a/crates/squid-engine/src/clean.rs b/crates/squid-engine/src/clean.rs index bc679d1..41c44b2 100644 --- a/crates/squid-engine/src/clean.rs +++ b/crates/squid-engine/src/clean.rs @@ -100,9 +100,10 @@ pub fn scan( && rule.needs_admin && !writable_by_us(&item.path) { - item = item - .locked(LockReason::NotOwned) - .with_note("needs admin rights — run squid with sudo to include it"); + item = item.locked(LockReason::NotOwned).with_note(format!( + "needs admin rights — {} to include it", + squid_core::elevation_hint() + )); } else if engine.is_whitelisted(&item.path) { item = item.locked(LockReason::Whitelisted); } else if let Some(reason) = engine.block_reason(&item) { diff --git a/crates/squid-engine/src/uninstall.rs b/crates/squid-engine/src/uninstall.rs index e975d45..77c60fb 100644 --- a/crates/squid-engine/src/uninstall.rs +++ b/crates/squid-engine/src/uninstall.rs @@ -145,9 +145,10 @@ pub fn build_plan( .locked(LockReason::AppRunning) .with_note("quit the app first"); } else if !crate::writable_by_us(&app.path) && !crate::is_root() { - bundle_item = bundle_item - .locked(LockReason::NotOwned) - .with_note("run squid uninstall with sudo to remove this copy"); + bundle_item = bundle_item.locked(LockReason::NotOwned).with_note(format!( + "{} to remove this copy", + squid_core::elevation_hint() + )); } plan.push(bundle_item);