Windows-friendly elevation hints
- new squid_core::elevation_hint(): sudo on Unix, elevated Administrator terminal on Windows; used by the locked-item notes in clean/uninstall and the user-only safety refusal. - the Permission error no longer tells Windows users to grant Full Disk Access (a macOS-only concept).main
parent
5619b1467d
commit
13dfcce22f
|
|
@ -5,6 +5,16 @@ use std::path::PathBuf;
|
|||
|
||||
pub type Result<T> = std::result::Result<T, SquidError>;
|
||||
|
||||
/// 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}")]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue