Skip to content

Commit 82e2d40

Browse files
committed
fix: take crates/utils/src/home_dir.rs from PR #42
1 parent a48b2de commit 82e2d40

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

crates/utils/src/home_dir.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
use dirs::home_dir;
44
use std::path::PathBuf;
55

6+
fn strip_unc_prefix(path: PathBuf) -> PathBuf {
7+
#[cfg(windows)]
8+
{
9+
let s = path.display().to_string();
10+
if let Some(stripped) = s.strip_prefix("\\\\?\\") {
11+
return PathBuf::from(stripped);
12+
}
13+
}
14+
path
15+
}
16+
617
/// Returns the path to the Clawcr configuration directory, which can be
718
/// specified by the `CLAWCR_HOME` environment variable. If not set, defaults to
819
/// `~/.clawcr`.
@@ -41,12 +52,14 @@ fn find_clawcr_home_from_env(clawcr_home_env: Option<&str>) -> std::io::Result<P
4152
format!("CLAWCR_HOME points to {val:?}, but that path is not a directory"),
4253
))
4354
} else {
44-
path.canonicalize().map_err(|err| {
45-
std::io::Error::new(
46-
err.kind(),
47-
format!("failed to canonicalize CLAWCR_HOME {val:?}: {err}"),
48-
)
49-
})
55+
path.canonicalize()
56+
.map(|p| strip_unc_prefix(p))
57+
.map_err(|err| {
58+
std::io::Error::new(
59+
err.kind(),
60+
format!("failed to canonicalize CLAWCR_HOME {val:?}: {err}"),
61+
)
62+
})
5063
}
5164
}
5265
None => {
@@ -112,10 +125,12 @@ mod tests {
112125
.expect("temp clawcr home path should be valid utf-8");
113126

114127
let resolved = find_clawcr_home_from_env(Some(temp_str)).expect("valid CLAWCR_HOME");
115-
let expected = temp_home
116-
.path()
117-
.canonicalize()
118-
.expect("canonicalize temp home");
128+
let expected = super::strip_unc_prefix(
129+
temp_home
130+
.path()
131+
.canonicalize()
132+
.expect("canonicalize temp home"),
133+
);
119134
assert_eq!(resolved, expected);
120135
}
121136

0 commit comments

Comments
 (0)