Skip to content

fix(package-manager): purge directory links on windows - #14798

Merged
zkochan merged 4 commits into
pnpm:mainfrom
shbernal:fix/purge-windows-dir-links
Sep 14, 2026
Merged

zkochan merged 4 commits into
pnpm:mainfrom
shbernal:fix/purge-windows-dir-links

Conversation

@shbernal

@shbernal shbernal commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #14790.

On Windows, purging an inconsistent node_modules fails with ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR ("Access is denied (os error 5)") as soon as it reaches a linked dependency. Switching nodeLinker from isolated to hoisted in an installed project reproduces it on 12.4.0 and 12.3.4. On 12.3.4 it is also the failure on the first install after upgrading from pnpm 11, which #14605 reproduced without a mechanism.

purge_modules_entry sent every entry that FileType::is_dir() rejects to std::fs::remove_file. On Windows, std counts a junction or a directory symlink as a symlink, and DeleteFileW cannot unlink a directory link.

pnpm_fs::remove_dirent already removes whatever occupies a path without following links, and is what pnpm clean, pnpm deploy, the injected-deps syncer and the virtual-store prune all use. The purge now calls it too, rather than growing a second copy of the platform dispatch. The local remove_modules_dir and remove_modules_file helpers go with the old dispatch: the purge was their only caller, and both already reported InstallError::RemoveModulesDir, so no error code or message changes. Other platforms take the same branches as before.

remove_dirent unlinked a Windows directory link with a bare fs::remove_dir, making it the one removal in pnpm-fs that gave up on the first sharing violation. It now goes through remove_symlink_dir like every other directory-link unlink in the crate, so an antivirus or indexer scan holding an entry open no longer aborts the purge. That matters here because an isolated layout makes almost every node_modules entry a link.

The TypeScript pnpm v11 CLI is not affected. It removes each entry with rimraf, which unlinks a directory link, and the same nodeLinker switch with pnpm 11.3.0 on Windows succeeds.

Verification

purge_removes_directory_links_without_following_them purges a directory that holds a link created by pnpm_fs::symlink_dir, a plain directory and a file. It asserts that all three are gone and that the link target is untouched. The Windows-specific dispatch itself is covered where it lives, by remove_dirent's junction, dangling-junction and file-symlink tests in pnpm/crates/fs/src/remove_dirent/tests.rs.

Rebased onto main, which had split prepare_modules_state.rs into submodules. The change now lives in prepare_modules_state/purge.rs.

On Linux: cargo nextest run -p pnpm-package-manager (697 passed), clippy, dylint, rustfmt and typos are all clean. Windows behavior is not exercised locally; Rust CI / Test / windows covers it.

Squash Commit Body

On Windows, the purge of an inconsistent `node_modules` sent every entry that
`FileType::is_dir()` rejects to `std::fs::remove_file`. std reports a junction or a
directory symlink as a symlink rather than a directory, and `DeleteFileW` refuses a
directory link with `ERROR_ACCESS_DENIED`. The purge therefore failed with
ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR at the first linked dependency. Any layout
change that purges a tree holding links hits it, such as switching `nodeLinker`, and on
12.3.4 so did the first install after upgrading from pnpm 11.

`purge_modules_entry` now removes each entry with `pnpm_fs::remove_dirent`, which unlinks
a directory-shaped link without following it, and which `pnpm clean`, `pnpm deploy`, the
injected-deps syncer and the virtual-store prune already use. The local
`remove_modules_dir` and `remove_modules_file` helpers go with the old dispatch: the purge
was their only caller and both already reported `InstallError::RemoveModulesDir`.

`remove_dirent` unlinked such a link with a bare `fs::remove_dir`, the one removal in
`pnpm-fs` that did not retry a transient Windows file lock. It now uses
`remove_symlink_dir`, as every other directory-link unlink in the crate does.

Closes pnpm/pnpm#14790

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Claude Code, claude-opus-5).

🤖 Generated with Claude Code

https://claude.ai/code/session_019YSqokw1VRnqKoh5SyS8tT


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Windows installation failures when clearing node_modules directories containing linked dependencies.
    • Improved cleanup so linked dependencies are removed without following links or affecting their original target files.
    • Install operations now handle mixed files, directories, and linked dependencies more reliably when resetting node_modules.
    • Resolved errors that could occur after changing the configured dependency linking strategy.

@shbernal
shbernal requested a review from zkochan as a code owner September 10, 2026 14:04
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 921dde94-cb7c-419e-8e5e-3be6fe29b282

📥 Commits

Reviewing files that changed from the base of the PR and between 71c4473 and 45460a1.

📒 Files selected for processing (1)
  • pnpm/crates/fs/src/remove_dirent.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The purge path now removes module entries with pnpm_fs::remove_dirent. Windows directory links use remove_symlink_dir, and a regression test confirms that external link targets remain intact. A patch changeset records the fix.

Changes

Windows directory-link purge

Layer / File(s) Summary
Directory-entry removal behavior
pnpm/crates/fs/src/remove_dirent.rs
Windows directory-shaped links now use remove_symlink_dir without removing their targets.
Directory-entry purge handling
pnpm/crates/package-manager/src/install/prepare_modules_state/purge.rs, .changeset/purge-windows-directory-links.md
purge_modules_entry uses pnpm_fs::remove_dirent for files and directories. The previous removal helpers were deleted. A patch changeset records the fix.
Symlink purge regression coverage
pnpm/crates/package-manager/src/install/prepare_modules_state/tests.rs
The test removes a directory, file, and symlinked dependency while confirming that the external link target remains present.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Assessment against linked issues

Objective Addressed Explanation
Remove a directory link during node_modules purging without deleting its target [#14790] ✅
Prevent ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR for the reported Windows purge scenario [#14790] ✅

Suggested labels: product: pacquet

Merge Risk: ⚪ Minimal · up to 45460

The Windows purge now removes directory links without deleting their targets, with no current merge-blocking risk identified.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Sep 10, 2026
@codecov-commenter

codecov-commenter commented Sep 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.91%. Comparing base (0b8a1cd) to head (45460a1).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...manager/src/install/prepare_modules_state/purge.rs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14798      +/-   ##
==========================================
+ Coverage   90.90%   90.91%   +0.01%     
==========================================
  Files        1265     1265              
  Lines      169561   169710     +149     
==========================================
+ Hits       154146   154299     +153     
+ Misses      15415    15411       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 45460a1e25f5

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.329 ± 0.120 2.220 2.522 1.69 ± 0.17
pacquet@main 2.365 ± 0.138 2.220 2.610 1.72 ± 0.18
pnpr@HEAD 1.376 ± 0.117 1.279 1.619 1.00
pnpr@main 1.389 ± 0.113 1.280 1.647 1.01 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.3288735905199998,
      "stddev": 0.11997394192812798,
      "median": 2.28378820132,
      "user": 1.26953054,
      "system": 1.4310260199999998,
      "min": 2.22012866782,
      "max": 2.52229090782
    },
    {
      "command": "pacquet@main",
      "mean": 2.36539566392,
      "stddev": 0.13815750434877544,
      "median": 2.30437387382,
      "user": 1.1460502399999999,
      "system": 1.4743536199999998,
      "min": 2.21960030082,
      "max": 2.60994745982
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.3764851709200001,
      "stddev": 0.11746618531667773,
      "median": 1.3224433593199998,
      "user": 1.0597176400000001,
      "system": 1.2979957199999999,
      "min": 1.2787567848199999,
      "max": 1.61871080282
    },
    {
      "command": "pnpr@main",
      "mean": 1.3890055409199997,
      "stddev": 0.11278004520316753,
      "median": 1.3739392828199999,
      "user": 1.08515024,
      "system": 1.2431946199999997,
      "min": 1.27960248082,
      "max": 1.64704241082
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 204.6 ± 12.4 190.2 225.0 1.00
pacquet@main 212.4 ± 15.5 189.1 240.5 1.04 ± 0.10
pnpr@HEAD 229.7 ± 7.6 213.9 239.9 1.12 ± 0.08
pnpr@main 233.8 ± 9.0 215.7 244.9 1.14 ± 0.08
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.20455314908000002,
      "stddev": 0.012354648974161893,
      "median": 0.20131047968000002,
      "user": 0.21891926,
      "system": 0.49425011999999996,
      "min": 0.19024204368,
      "max": 0.22500150168
    },
    {
      "command": "pacquet@main",
      "mean": 0.21238745608,
      "stddev": 0.015483412701924815,
      "median": 0.21160136318,
      "user": 0.21959716,
      "system": 0.5274176199999999,
      "min": 0.18912830968,
      "max": 0.24048582668000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.22968094758,
      "stddev": 0.007561343431055922,
      "median": 0.23163955168,
      "user": 0.23664505999999993,
      "system": 0.54199682,
      "min": 0.21394527568000002,
      "max": 0.23987197668000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.23377574118000002,
      "stddev": 0.009032845795195607,
      "median": 0.23699374468,
      "user": 0.24636856,
      "system": 0.53724702,
      "min": 0.21567780868,
      "max": 0.24493543168
    }
  ]
}

Scenario: Isolated linker: repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 6.4 ± 0.3 5.8 9.0 1.00
pacquet@main 6.4 ± 0.5 5.6 8.6 1.01 ± 0.09
pnpr@HEAD 6.5 ± 0.4 5.8 9.1 1.02 ± 0.08
pnpr@main 6.5 ± 0.3 5.8 8.5 1.02 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.00635651160389262,
      "stddev": 0.00031644793480040936,
      "median": 0.00631972852,
      "user": 0.004126983221476513,
      "system": 0.002607523221476511,
      "min": 0.005811534520000001,
      "max": 0.008996690520000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.006430695417435895,
      "stddev": 0.0004556653073455884,
      "median": 0.006378633520000001,
      "user": 0.003793158974358973,
      "system": 0.003046997641025642,
      "min": 0.005606189520000001,
      "max": 0.00860269152
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.006491011040725384,
      "stddev": 0.0003998696372855715,
      "median": 0.0064497170200000006,
      "user": 0.003959826424870471,
      "system": 0.0029475586528497403,
      "min": 0.005813778520000001,
      "max": 0.00906420852
    },
    {
      "command": "pnpr@main",
      "mean": 0.006468315408040716,
      "stddev": 0.0003157007489760411,
      "median": 0.00647018052,
      "user": 0.003972629770992367,
      "system": 0.0029664831552162884,
      "min": 0.00581141352,
      "max": 0.00853830052
    }
  ]
}

Scenario: Isolated linker: repeat install, cold cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 8.9 ± 1.7 5.9 15.4 1.33 ± 0.26
pacquet@main 8.1 ± 1.5 6.0 13.1 1.21 ± 0.23
pnpr@HEAD 7.0 ± 0.6 5.8 9.3 1.05 ± 0.10
pnpr@main 6.7 ± 0.4 5.8 8.2 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.008887302170825695,
      "stddev": 0.0016817623407526588,
      "median": 0.00875929618,
      "user": 0.005400047828746176,
      "system": 0.003994139204892967,
      "min": 0.00592052218,
      "max": 0.015397202180000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.00807559759666667,
      "stddev": 0.001474927236707184,
      "median": 0.0075405296800000006,
      "user": 0.004750453333333334,
      "system": 0.003815195333333333,
      "min": 0.00596871218,
      "max": 0.013056871180000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.006991271350967744,
      "stddev": 0.0005731663926740166,
      "median": 0.00692194618,
      "user": 0.0042137780645161325,
      "system": 0.003200398967741936,
      "min": 0.00579721118,
      "max": 0.009275762180000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.006669953119297127,
      "stddev": 0.00036570433978948746,
      "median": 0.0066390571800000004,
      "user": 0.004057773674121406,
      "system": 0.002957801150159743,
      "min": 0.0058238911800000005,
      "max": 0.00820255318
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.445 ± 0.060 2.401 2.612 1.68 ± 0.13
pacquet@main 2.426 ± 0.023 2.388 2.459 1.66 ± 0.12
pnpr@HEAD 1.517 ± 0.117 1.366 1.649 1.04 ± 0.11
pnpr@main 1.458 ± 0.107 1.357 1.635 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.44468295936,
      "stddev": 0.060228695277514635,
      "median": 2.42689131986,
      "user": 1.6234037000000001,
      "system": 1.5111661399999998,
      "min": 2.40064726036,
      "max": 2.61183324436
    },
    {
      "command": "pacquet@main",
      "mean": 2.42619709686,
      "stddev": 0.02301876064525038,
      "median": 2.42743700486,
      "user": 1.5916485999999999,
      "system": 1.5179523400000001,
      "min": 2.38841196436,
      "max": 2.45943594036
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5168546905600002,
      "stddev": 0.11678296398624739,
      "median": 1.52382437786,
      "user": 1.0081923,
      "system": 1.1784194399999999,
      "min": 1.36617522036,
      "max": 1.64879426336
    },
    {
      "command": "pnpr@main",
      "mean": 1.45778703076,
      "stddev": 0.10739673989599238,
      "median": 1.4054966068599999,
      "user": 1.0096124,
      "system": 1.24437894,
      "min": 1.35670359536,
      "max": 1.63472887536
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 331.1 ± 16.8 304.7 360.0 1.30 ± 0.08
pacquet@main 329.1 ± 11.1 313.8 355.4 1.29 ± 0.07
pnpr@HEAD 297.8 ± 59.8 254.5 412.8 1.17 ± 0.24
pnpr@main 254.7 ± 10.2 242.1 273.8 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.33106532454000004,
      "stddev": 0.01679952093259483,
      "median": 0.32858914034,
      "user": 0.5061542800000001,
      "system": 0.7715857599999999,
      "min": 0.30466297034,
      "max": 0.36004117334
    },
    {
      "command": "pacquet@main",
      "mean": 0.32912047344,
      "stddev": 0.011141242667664482,
      "median": 0.32832894584,
      "user": 0.5024805800000001,
      "system": 0.7707156599999999,
      "min": 0.31382728334,
      "max": 0.35538835834
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29779935534,
      "stddev": 0.05977787064690212,
      "median": 0.26873254084,
      "user": 0.24896948000000005,
      "system": 0.57402876,
      "min": 0.25449504934,
      "max": 0.41275343934000003
    },
    {
      "command": "pnpr@main",
      "mean": 0.25473452354000004,
      "stddev": 0.010190836162756216,
      "median": 0.25119186634,
      "user": 0.19963238,
      "system": 0.49106096,
      "min": 0.24210815634,
      "max": 0.27382120734
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.608 ± 0.100 1.521 1.790 6.15 ± 0.45
pacquet@main 1.537 ± 0.013 1.517 1.557 5.88 ± 0.23
pnpr@HEAD 0.281 ± 0.008 0.270 0.300 1.08 ± 0.05
pnpr@main 0.261 ± 0.010 0.239 0.275 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.6083034132000003,
      "stddev": 0.10003234960454413,
      "median": 1.5584901173,
      "user": 0.9243144799999999,
      "system": 1.0710800800000002,
      "min": 1.5212209378000001,
      "max": 1.7899662558000002
    },
    {
      "command": "pacquet@main",
      "mean": 1.5366176996000003,
      "stddev": 0.012866380877659714,
      "median": 1.5338610983,
      "user": 0.76044588,
      "system": 0.9138235800000001,
      "min": 1.5173046188000001,
      "max": 1.5568412498
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.2810947327,
      "stddev": 0.00828171582549073,
      "median": 0.2794058283,
      "user": 0.22821248,
      "system": 0.53377908,
      "min": 0.2702996878,
      "max": 0.2999598208
    },
    {
      "command": "pnpr@main",
      "mean": 0.26135051400000003,
      "stddev": 0.009934824983795344,
      "median": 0.2624247983,
      "user": 0.20032158,
      "system": 0.49028397999999995,
      "min": 0.23948896880000003,
      "max": 0.27464154080000003
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 243.8 ± 14.0 221.7 267.4 2.47 ± 0.15
pacquet@main 240.4 ± 14.7 221.7 261.5 2.44 ± 0.16
pnpr@HEAD 98.5 ± 2.3 94.1 102.3 1.00
pnpr@main 98.6 ± 2.5 92.0 104.2 1.00 ± 0.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2438354586218182,
      "stddev": 0.014045658888137717,
      "median": 0.24076849644,
      "user": 0.2620207618181818,
      "system": 0.09359582181818182,
      "min": 0.22169282844000002,
      "max": 0.26736375244
    },
    {
      "command": "pacquet@main",
      "mean": 0.24036042794,
      "stddev": 0.014679776042061249,
      "median": 0.23868426194000003,
      "user": 0.24701732999999995,
      "system": 0.10211113999999999,
      "min": 0.22172421944,
      "max": 0.26154500844
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09854494511857141,
      "stddev": 0.002308066503507741,
      "median": 0.09837289544000001,
      "user": 0.045957758571428566,
      "system": 0.014813211428571426,
      "min": 0.09405989144000002,
      "max": 0.10234380844000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.09858239354000002,
      "stddev": 0.0025062794725023607,
      "median": 0.09853069244000001,
      "user": 0.040969146666666664,
      "system": 0.020051339999999994,
      "min": 0.09195761844000001,
      "max": 0.10419536944
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 640.0 ± 27.9 581.8 674.7 1.02 ± 0.10
pacquet@main 626.4 ± 53.0 530.1 729.7 1.00
pnpm@HEAD 3468.6 ± 116.6 3285.4 3650.0 5.54 ± 0.50
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6400330249355555,
      "stddev": 0.02791765551951298,
      "median": 0.64652356538,
      "user": 0.6869650533333334,
      "system": 0.17582687555555554,
      "min": 0.58182556238,
      "max": 0.67465104538
    },
    {
      "command": "pacquet@main",
      "mean": 0.6264218782688888,
      "stddev": 0.05297321237758546,
      "median": 0.61882568738,
      "user": 0.6797390533333333,
      "system": 0.16073420888888887,
      "min": 0.53014018638,
      "max": 0.72971638238
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.468579621268889,
      "stddev": 0.116551371485737,
      "median": 3.49298866338,
      "user": 5.5321526088888895,
      "system": 0.22736432,
      "min": 3.28535352938,
      "max": 3.65002565138
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.380 ± 0.122 4.277 4.661 1.30 ± 0.05
pacquet@main 4.371 ± 0.159 4.252 4.747 1.29 ± 0.06
pnpr@HEAD 3.384 ± 0.055 3.331 3.499 1.00 ± 0.03
pnpr@main 3.382 ± 0.079 3.327 3.535 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.380427899600001,
      "stddev": 0.12164066176160356,
      "median": 4.339783989800001,
      "user": 1.3041399200000001,
      "system": 1.4259961399999999,
      "min": 4.2769937728,
      "max": 4.661413088800001
    },
    {
      "command": "pacquet@main",
      "mean": 4.371059754799999,
      "stddev": 0.15917602841181835,
      "median": 4.3037587963,
      "user": 1.2128584199999999,
      "system": 1.4234160399999995,
      "min": 4.2524680318,
      "max": 4.746759183800001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.3836058049,
      "stddev": 0.05476834352959173,
      "median": 3.3689317993,
      "user": 1.16240672,
      "system": 1.33189994,
      "min": 3.3308857248,
      "max": 3.4987300748
    },
    {
      "command": "pnpr@main",
      "mean": 3.3822515569000005,
      "stddev": 0.0794230905693952,
      "median": 3.3443312038,
      "user": 1.16019172,
      "system": 1.31468144,
      "min": 3.3270177518,
      "max": 3.5352751468
    }
  ]
}

Scenario: GVS linker: fresh restore, hot cache + hot store

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 117.4 ± 7.6 108.0 141.1 1.00
pacquet@main 118.2 ± 7.9 103.6 135.0 1.01 ± 0.09
pnpr@HEAD 127.7 ± 6.4 115.6 137.8 1.09 ± 0.09
pnpr@main 121.7 ± 2.8 118.2 128.3 1.04 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.11737820700444446,
      "stddev": 0.007599712532989971,
      "median": 0.11549567306,
      "user": 0.14141576666666666,
      "system": 0.12771035111111112,
      "min": 0.10802116406000001,
      "max": 0.14109601606000002
    },
    {
      "command": "pacquet@main",
      "mean": 0.11824517486952384,
      "stddev": 0.007939633440253177,
      "median": 0.11868475406000001,
      "user": 0.1466871476190476,
      "system": 0.13396283523809524,
      "min": 0.10363644106,
      "max": 0.13500072406000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.12767508142842104,
      "stddev": 0.006409140310656865,
      "median": 0.12798867406000003,
      "user": 0.14584688947368418,
      "system": 0.1353585294736842,
      "min": 0.11562753006,
      "max": 0.13776233406000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.12170628077428576,
      "stddev": 0.0027926920252034477,
      "median": 0.12127411106000001,
      "user": 0.1442533380952381,
      "system": 0.1299574066666667,
      "min": 0.11821902006,
      "max": 0.12826794706000003
    }
  ]
}

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/14798
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
108.02 ms
(-12.66%)Baseline: 123.68 ms
148.42 ms
(72.78%)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,400.65 ms
(-3.47%)Baseline: 2,486.98 ms
2,984.37 ms
(80.44%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,521.22 ms
(-3.34%)Baseline: 1,573.82 ms
1,888.59 ms
(80.55%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
304.66 ms
(-21.23%)Baseline: 386.75 ms
464.10 ms
(65.65%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
221.69 ms
(-0.74%)Baseline: 223.34 ms
268.01 ms
(82.72%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,220.13 ms
(-4.98%)Baseline: 2,336.47 ms
2,803.76 ms
(79.18%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,276.99 ms
(-3.22%)Baseline: 4,419.33 ms
5,303.20 ms
(80.65%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
190.24 ms
(-15.72%)Baseline: 225.72 ms
270.87 ms
(70.23%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
581.83 ms
(-3.00%)Baseline: 599.82 ms
719.79 ms
(80.83%)
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
🚷 view threshold
5.92 ms
(-11.55%)Baseline: 6.69 ms
8.03 ms
(73.70%)
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
🚷 view threshold
5.81 ms
(-14.56%)Baseline: 6.80 ms
8.16 ms
(71.20%)
🐰 View full continuous benchmarking report in Bencher

shbernal and others added 2 commits September 14, 2026 02:27
On Windows, the purge of an inconsistent `node_modules` sent every entry that
`FileType::is_dir()` rejects to `std::fs::remove_file`. std reports a junction or a directory
symlink as a symlink rather than a directory, and `DeleteFileW` refuses a directory link with
`ERROR_ACCESS_DENIED`. The purge therefore failed with ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR
at the first linked dependency. Any layout change that purges a tree holding links hits it, such
as switching `nodeLinker`, and on 12.3.4 so did the first install after upgrading from pnpm 11.

Directory-shaped entries now go through `remove_modules_dir`, which already unlinks them with
`pnpm_fs::remove_symlink_dir` on Windows. Other platforms are unchanged, because the symlink check
only runs on Windows and `remove_file` unlinks a symlink everywhere else.

Closes pnpm#14790
`pnpm_fs::remove_dirent` already removes whatever occupies a path without
following links, including the Windows directory symlinks and junctions
`std::fs::remove_file` refuses, and it is covered by junction, dangling-link
and file-symlink tests. Calling it from `purge_modules_entry` drops the local
dispatch this PR had grown a predicate for.

`remove_modules_dir` and `remove_modules_file` go with it. The purge was their
only caller and both already reported `InstallError::RemoveModulesDir`, so no
error code or message changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019YSqokw1VRnqKoh5SyS8tT
@zkochan
zkochan force-pushed the fix/purge-windows-dir-links branch from dfa9e0a to 15dc97b Compare September 14, 2026 00:41
@zkochan

zkochan commented Sep 14, 2026

Copy link
Copy Markdown
Member

Rebased onto main and reworked the fix. Head is now 15dc97bde0.

Rebase. The branch was 30 commits behind, and main had split prepare_modules_state.rs into prepare_modules_state/{purge,up_to_date,tests}.rs (PRs #14804, #14792, #14872, #14875). Both files in the PR conflicted. The production change now lives in prepare_modules_state/purge.rs, and the test's imports were merged onto the new module path.

Reuse instead of a new predicate. pnpm_fs::remove_dirent already does exactly this job. Its doc comment names this bug, it was added for the sibling issue #13694, and it is already called from pnpm clean, pnpm deploy, the injected-deps syncer, and prune_virtual_store.rs in this same crate. So purge_modules_entry now calls it rather than carrying a second copy of the platform dispatch.

That also lets remove_modules_dir and remove_modules_file go. The purge was their only caller, and both already reported InstallError::RemoveModulesDir, so no error code or message changes. Net effect on the crate is +2/-24 lines instead of +14.

One deliberate behavior difference worth flagging: remove_modules_dir wrapped its Windows remove_dir in retry_transient_file_locks, and remove_dirent does not. That retry never covered the case being fixed here, since directory links reached remove_file and failed outright, and the real-directory path went to an unretried remove_dir_all either way. If the retry is wanted, the right home for it is inside remove_dirent, where all five callers would get it.

Changeset rewritten to one idea per sentence, with the issue link last.

Checks on Linux: cargo nextest run -p pnpm-package-manager passes all 697 tests, and clippy, dylint, rustfmt and typos are clean. Windows behavior is left to Rust CI / Test / windows; the dispatch itself is covered by remove_dirent's junction and dangling-junction tests.


Written by an agent (Claude Code, claude-opus-5).

@qodo-code-review

qodo-code-review Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. One changeset blends old and new behavior ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The first sentence in the changeset uses no longer fails, embedding the former failure in the
statement of current behavior. When this bug-fix text becomes release notes, readers must infer the
behavioral transition instead of receiving a separate past-tense account followed by the current
guarantee.
Code

.changeset/purge-windows-directory-links.md[5]

+On Windows, `pnpm install` no longer fails with `ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR` when it clears a `node_modules` directory that holds linked dependencies. Changing `nodeLinker` in an installed project hit this [#14790](https://github.com/pnpm/pnpm/issues/14790).
Relevance

●●● Strong

Recent changeset reviews accepted separating prior failures from current guarantees, including the
same compliance rule.

PR-#14847
PR-#14179

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 3058498 requires previous buggy behavior to appear in a separate past-tense
sentence. The added changeset instead combines the former failure and corrected result in `pnpm
install no longer fails`.

Rule 3058498: Describe previous buggy behavior in a separate past-tense sentence
.changeset/purge-windows-directory-links.md[5-5]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The bug-fix changeset combines the previous failure and corrected behavior through `no longer fails`, rather than describing the former behavior in its own past-tense sentence.

## Fix Focus Areas
- .changeset/purge-windows-directory-links.md[5-5]

## Recommended Fix
Rewrite the entry as two sentences. First state that `pnpm install` previously failed on Windows while clearing linked dependencies, then state that it now completes that purge without this error.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 37 rules
✅ Cross-repo context — repo relationships
Review mode: 🚀 Fast: This is a small, localized Windows filesystem-removal change affecting one dispatch path, with no broad or security-sensitive logic requiring redundant review.

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

The entry named the trigger for the bug but not what pnpm did, leaving
the reader to infer the failure from `no longer fails`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019YSqokw1VRnqKoh5SyS8tT
@zkochan

zkochan commented Sep 14, 2026

Copy link
Copy Markdown
Member

Qodo's rule 3058498 finding is fair, so it is fixed in 71c44733e4. The entry named the trigger for the bug but never said what pnpm actually did, which left the failure to be inferred from no longer fails. It now follows the shape the recently merged entries use, such as the workspace: peers one for #14770: current behavior, then the old behavior in its own past-tense sentence, then the issue link.

On Windows, `pnpm install` no longer fails with `ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR`
when it clears a `node_modules` directory that holds linked dependencies. pnpm could not
remove a linked dependency there, so changing `nodeLinker` in an installed project aborted
the install.

Qodo reported no bugs and no code suggestions.


Written by an agent (Claude Code, claude-opus-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 71c4473

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/14798
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
115.63 ms
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,366.18 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
270.30 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
254.50 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
94.06 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,278.76 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,330.89 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
213.95 ms
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
5.80 ms
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
5.81 ms
🐰 View full continuous benchmarking report in Bencher

`remove_dirent` called `fs::remove_dir` directly, so a link unlink was the
one removal in the crate that gave up on the first sharing violation. Every
other directory-link unlink goes through `remove_symlink_dir`, which retries
a transient Windows file lock; this one now does too.

It matters most for the `node_modules` purge, where an isolated layout makes
almost every entry a link, and an antivirus or indexer scan holding one open
would abort the install.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019YSqokw1VRnqKoh5SyS8tT
@zkochan

zkochan commented Sep 14, 2026

Copy link
Copy Markdown
Member

Correcting something I said earlier in this thread. I claimed the Windows-only branch in remove_modules_dir cost nothing to drop. That was wrong for the case this PR fixes, and 45460a1e25 fixes it.

Where that branch came from. It was written in #12536, the same commit as the is_dir() dispatch:

if entry.file_type().is_ok_and(|t| t.is_dir()) {
    #[cfg(windows)]
    let is_removed = pacquet_fs::remove_symlink_dir(&entry.path()).is_ok();
    ...

It is an attempt at exactly this bug, placed inside the is_dir() branch that a directory link never enters on Windows. So as a link handler it was dead from day one, which is why the purge still failed.

But it did carry something real: the retry. remove_symlink_dir wraps its remove_dir in retry_transient_file_locks, so a sharing or lock violation from an antivirus or indexer scan is retried with a bounded backoff. remove_dirent called a bare fs::remove_dir, making it the one removal in pnpm-fs that gives up on the first such error. Routing the purge through it therefore took retry coverage away from directory links, and an isolated node_modules is almost entirely directory links. On Windows that is the common shape, not an edge case.

The fix is one line in remove_dirent: use remove_symlink_dir, as force_symlink and create_dir_all_replacing_reparse_point in the same crate already do. All five callers gain it, and pnpm clean, pnpm deploy, the injected-deps syncer and the virtual-store prune had the same gap.

Worth noting the original is_directory_shaped approach had the opposite problem: on a failed remove_symlink_dir it fell through to remove_dir_all on the link itself. Going through remove_dirent removes that fallback.

cargo clippy -p pnpm-fs --all-targets --target x86_64-pc-windows-msvc -- -D warnings is clean, so the #[cfg(windows)] path is compiled and linted rather than assumed. pnpm-fs (101) and the purge tests pass on Linux.


Written by an agent (Claude Code, claude-opus-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 45460a1

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@greptile-apps

greptile-apps Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the shared removal helper correctly handles ordinary entries and Windows directory links without following their targets.

Reviews (1) · Last reviewed commit: "fix(fs): unlink a Windows directory link..."

@zkochan
zkochan merged commit ec0023b into pnpm:main Sep 14, 2026
52 checks passed
biisal pushed a commit to biisal/pnpm that referenced this pull request Sep 15, 2026
On Windows, the purge of an inconsistent `node_modules` sent every entry that
`FileType::is_dir()` rejects to `std::fs::remove_file`. std reports a junction or a
directory symlink as a symlink rather than a directory, and `DeleteFileW` refuses a
directory link with `ERROR_ACCESS_DENIED`. The purge therefore failed with
ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR at the first linked dependency. Any layout
change that purges a tree holding links hits it, such as switching `nodeLinker`, and on
12.3.4 so did the first install after upgrading from pnpm 11.

`purge_modules_entry` now removes each entry with `pnpm_fs::remove_dirent`, which unlinks
a directory-shaped link without following it, and which `pnpm clean`, `pnpm deploy`, the
injected-deps syncer and the virtual-store prune already use. The local
`remove_modules_dir` and `remove_modules_file` helpers go with the old dispatch: the purge
was their only caller and both already reported `InstallError::RemoveModulesDir`.

`remove_dirent` unlinked such a link with a bare `fs::remove_dir`, the one removal in
`pnpm-fs` that did not retry a transient Windows file lock. It now uses
`remove_symlink_dir`, as every other directory-link unlink in the crate does.

Closes pnpm#14790

---------

Co-authored-by: Zoltan Kochan <[email protected]>
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
On Windows, the purge of an inconsistent `node_modules` sent every entry that
`FileType::is_dir()` rejects to `std::fs::remove_file`. std reports a junction or a
directory symlink as a symlink rather than a directory, and `DeleteFileW` refuses a
directory link with `ERROR_ACCESS_DENIED`. The purge therefore failed with
ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR at the first linked dependency. Any layout
change that purges a tree holding links hits it, such as switching `nodeLinker`, and on
12.3.4 so did the first install after upgrading from pnpm 11.

`purge_modules_entry` now removes each entry with `pnpm_fs::remove_dirent`, which unlinks
a directory-shaped link without following it, and which `pnpm clean`, `pnpm deploy`, the
injected-deps syncer and the virtual-store prune already use. The local
`remove_modules_dir` and `remove_modules_file` helpers go with the old dispatch: the purge
was their only caller and both already reported `InstallError::RemoveModulesDir`.

`remove_dirent` unlinked such a link with a bare `fs::remove_dir`, the one removal in
`pnpm-fs` that did not retry a transient Windows file lock. It now uses
`remove_symlink_dir`, as every other directory-link unlink in the crate does.

Closes pnpm#14790

---------

Co-authored-by: Zoltan Kochan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: purging node_modules fails with ERR_PNPM_PACKAGE_MANAGER_REMOVE_MODULES_DIR when it holds a directory link

3 participants