|
3 | 3 | use dirs::home_dir; |
4 | 4 | use std::path::PathBuf; |
5 | 5 |
|
| 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 | + |
6 | 17 | /// Returns the path to the Clawcr configuration directory, which can be |
7 | 18 | /// specified by the `CLAWCR_HOME` environment variable. If not set, defaults to |
8 | 19 | /// `~/.clawcr`. |
@@ -41,12 +52,14 @@ fn find_clawcr_home_from_env(clawcr_home_env: Option<&str>) -> std::io::Result<P |
41 | 52 | format!("CLAWCR_HOME points to {val:?}, but that path is not a directory"), |
42 | 53 | )) |
43 | 54 | } 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 | + }) |
50 | 63 | } |
51 | 64 | } |
52 | 65 | None => { |
@@ -112,10 +125,12 @@ mod tests { |
112 | 125 | .expect("temp clawcr home path should be valid utf-8"); |
113 | 126 |
|
114 | 127 | 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 | + ); |
119 | 134 | assert_eq!(resolved, expected); |
120 | 135 | } |
121 | 136 |
|
|
0 commit comments