MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / home_dir

Function home_dir

crates/chat-cli/src/util/paths.rs:75–111  ·  view source on GitHub ↗

The directory of the users home - Linux: /home/Alice - MacOS: /Users/Alice - Windows: C:\Users\Alice

(#[cfg_attr(windows, allow(unused_variables))] os: &Os)

Source from the content-addressed store, hash-verified

73/// - MacOS: /Users/Alice
74/// - Windows: C:\Users\Alice
75pub fn home_dir(#[cfg_attr(windows, allow(unused_variables))] os: &Os) -> Result<PathBuf> {
76 #[cfg(unix)]
77 match cfg!(test) {
78 true => os
79 .env
80 .get("HOME")
81 .map_err(|_err| DirectoryError::NoHomeDirectory)
82 .and_then(|h| {
83 if h.is_empty() {
84 Err(DirectoryError::NoHomeDirectory)
85 } else {
86 Ok(h)
87 }
88 })
89 .map(PathBuf::from)
90 .map(|p| os.fs.chroot_path(p)),
91 false => dirs::home_dir().ok_or(DirectoryError::NoHomeDirectory),
92 }
93
94 #[cfg(windows)]
95 match cfg!(test) {
96 true => os
97 .env
98 .get("USERPROFILE")
99 .map_err(|_err| DirectoryError::NoHomeDirectory)
100 .and_then(|h| {
101 if h.is_empty() {
102 Err(DirectoryError::NoHomeDirectory)
103 } else {
104 Ok(h)
105 }
106 })
107 .map(PathBuf::from)
108 .map(|p| os.fs.chroot_path(p)),
109 false => dirs::home_dir().ok_or(DirectoryError::NoHomeDirectory),
110 }
111}
112
113/// Get the macos tempdir from the `confstr` function
114#[cfg(target_os = "macos")]

Callers 12

agents_dirMethod · 0.70
prompts_dirMethod · 0.70
mcp_configMethod · 0.70
shadow_repo_dirMethod · 0.70
cli_bash_historyMethod · 0.70
global_contextMethod · 0.70
profiles_dirMethod · 0.70
knowledge_bases_dirMethod · 0.70
mcp_auth_dirMethod · 0.70
homeMethod · 0.50
loadMethod · 0.50
get_default_base_dirFunction · 0.50

Calls 4

mapMethod · 0.80
chroot_pathMethod · 0.80
getMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected