Skip to content

Commit 9e0c88f

Browse files
elrrrrrrrclaude
andcommitted
fix(pm): ensure cache dir is on same drive as project on Windows
Hardlinks cannot cross drive boundaries on Windows. When cache is on C: but project is on D:, utoo falls back to copy (very slow). Detect cross-drive and use a cache dir on the project's drive instead (e.g. D:\.cache\nm). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 69b4ce3 commit 9e0c88f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

crates/pm/src/util/user_config.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,23 @@ pub async fn set_cache_dir(cache_dir: Option<String>) {
140140
}
141141

142142
pub fn get_cache_dir() -> PathBuf {
143-
PathBuf::from(CACHE_DIR.get_sync())
143+
let cache = PathBuf::from(CACHE_DIR.get_sync());
144+
145+
// On Windows, hardlinks cannot cross drive boundaries.
146+
// If cache (e.g. C:\.cache\nm) is on a different drive than cwd (e.g. D:\project),
147+
// use a cache dir on the project's drive instead.
148+
#[cfg(windows)]
149+
if let Ok(cwd) = std::env::current_dir() {
150+
let cache_drive = cache.components().next().map(|c| c.as_os_str().to_ascii_uppercase());
151+
let cwd_drive = cwd.components().next().map(|c| c.as_os_str().to_ascii_uppercase());
152+
if cache_drive != cwd_drive {
153+
if let Some(drive) = cwd.components().next() {
154+
return PathBuf::from(drive.as_os_str()).join(".cache").join("nm");
155+
}
156+
}
157+
}
158+
159+
cache
144160
}
145161

146162
// Package.json cache — keyed by directory path, covers root + workspace members.

0 commit comments

Comments
 (0)