use std::path::Path;
const SENSITIVE_COMPONENTS: &[&str] = &[
".ssh",
".gnupg",
".aws",
".azure",
".kube",
".docker",
".password-store",
".mozilla",
".thunderbird",
];
#[cfg(unix)]
const SYSTEM_PREFIXES: &[&str] = &["/etc", "/usr", "/bin", "/sbin", "/boot", "/proc", "/sys"];
#[cfg(not(unix))]
const SYSTEM_PREFIXES: &[&str] = &[
"C:\\Windows",
"C:\\Program Files",
"C:\\Program Files (x86)",
];
pub fn sensitive_warning(path: &Path) -> Option<&'static str> {
let path_str = path.to_string_lossy();
for prefix in SYSTEM_PREFIXES {
if path_str.starts_with(prefix) {
return Some("system_directory");
}
}
for component in path.components() {
let name = component.as_os_str().to_string_lossy();
if SENSITIVE_COMPONENTS.contains(&name.as_ref()) {
return Some("credential_directory");
}
if name == ".config" {
return Some("hidden_configuration_directory");
}
}
None
}