Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(npm): use ntfs junctions in node_modules folder on Windows #16061

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ zstd = '=0.11.2'

[target.'cfg(windows)'.dependencies]
fwdansi = "=1.1.0"
junction = "=0.2.0"
winapi = { version = "=0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] }

[dev-dependencies]
Expand Down
30 changes: 30 additions & 0 deletions cli/npm/resolvers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,39 @@ fn symlink_package_dir(

// need to delete the previous symlink before creating a new one
let _ignore = fs::remove_dir_all(new_path);

#[cfg(windows)]
return junction_or_symlink_dir(old_path, new_path);
dsherret marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(not(windows))]
fs_util::symlink_dir(old_path, new_path)
}

#[cfg(windows)]
fn junction_or_symlink_dir(
old_path: &Path,
new_path: &Path,
) -> Result<(), AnyError> {
// Use junctions because they're supported on ntfs file systems without
// needing to elevate privileges on Windows
match junction::create(old_path, new_path) {
Ok(()) => Ok(()),
Err(junction_err) => {
match fs_util::symlink_dir(old_path, new_path) {
Ok(()) => Ok(()),
Err(symlink_err) => bail!(
concat!(
"Attempted to junction and failed. Then attempted to symlink and also failed.\n\n",
"Junction error:\n{:#}\n\nSymlink error:\n{:#}\n\n",
"Maybe try enabling developer mode on your machine?"
dsherret marked this conversation as resolved.
Show resolved Hide resolved
),
junction_err,
symlink_err,
),
}
}
}
}

fn join_package_name(path: &Path, package_name: &str) -> PathBuf {
let mut path = path.to_path_buf();
// ensure backslashes are used on windows
Expand Down