1use std::path::Path;
7
8const SENSITIVE_COMPONENTS: &[&str] = &[
11 ".ssh",
12 ".gnupg",
13 ".aws",
14 ".azure",
15 ".kube",
16 ".docker",
17 ".password-store",
18 ".mozilla",
19 ".thunderbird",
20];
21
22#[cfg(unix)]
24const SYSTEM_PREFIXES: &[&str] = &["/etc", "/usr", "/bin", "/sbin", "/boot", "/proc", "/sys"];
25
26#[cfg(not(unix))]
27const SYSTEM_PREFIXES: &[&str] = &[
28 "C:\\Windows",
29 "C:\\Program Files",
30 "C:\\Program Files (x86)",
31];
32
33pub fn sensitive_warning(path: &Path) -> Option<&'static str> {
36 let path_str = path.to_string_lossy();
37 for prefix in SYSTEM_PREFIXES {
38 if path_str.starts_with(prefix) {
39 return Some("system_directory");
40 }
41 }
42 for component in path.components() {
43 let name = component.as_os_str().to_string_lossy();
44 if SENSITIVE_COMPONENTS.contains(&name.as_ref()) {
45 return Some("credential_directory");
46 }
47 if name == ".config" {
49 return Some("hidden_configuration_directory");
50 }
51 }
52 None
53}