diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-03-07 23:40:19 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-07 13:10:19 -0500 |
commit | e0c9102b49ab333e0229247c446d12e27750785c (patch) | |
tree | b9e8ab4b6980cffe0de3aadb518a1ebbcd2017fb /cli/npm/managed/resolvers/local.rs | |
parent | 8df47882c942d3cf5558fee05f02629025e46ae7 (diff) |
perf: hard link npm cache (#22773)
Diffstat (limited to 'cli/npm/managed/resolvers/local.rs')
-rw-r--r-- | cli/npm/managed/resolvers/local.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index 88368cdd2..34e0fae09 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -332,8 +332,12 @@ async fn sync_resolution_with_fs( .with_context(|| format!("Creating '{}'", folder_path.display()))?; let cache_folder = cache .package_folder_for_name_and_version(&package.id.nv, ®istry_url); - // for now copy, but in the future consider hard linking - copy_dir_recursive(&cache_folder, &package_path)?; + if hard_link_dir_recursive(&cache_folder, &package_path).is_err() { + // Fallback to copying the directory. + // + // Also handles EXDEV when when trying to hard link across volumes. + copy_dir_recursive(&cache_folder, &package_path)?; + } // write out a file that indicates this folder has been initialized fs::write(initialized_file, "")?; // finally stop showing the progress bar |