Files
hermes-agent/scripts
David Metcalfe d6a711c783 fix(win): CIM-based PS in-use check and same-volume staging swap
Adopts two improvements from #81586 (kshitijk4poor), with one correction:

- Test-ManagedNodeInUse now queries Win32_Process (ExecutablePath +
  CommandLine substring) instead of Get-Process .Path: a cmd.exe wrapper
  running npm.cmd from the tree reports its own exe in System32, so the
  tree path shows up only in the command line. Win32_Process.CommandLine
  works on Windows PowerShell 5.1 and 7+, unlike the Get-Process
  .CommandLine ETS property (7.4+ only); a single CIM query also beats a
  per-process property access loop. This closes the gap flagged by the
  triage bot on #81500 (Update-ManagedNpm's only in-use protection is
  this pre-check).
- Test-Node stages the extracted tree to a sibling node.new-* before the
  swap, so the final swap is a same-volume rename (atomic) instead of a
  cross-volume Move-Item (copy+delete, non-atomic).

The mtime-touch ordering from #81586 was NOT adopted: touching the backup
only after the swap succeeds leaves it at its old (long-lived-tree) mtime
for the whole swap window, which the age-gated litter sweep (st_mtime <
cutoff) removes — reopening the concurrent-sweep race the touch exists to
close. The touch stays immediately after the backup rename.

Co-authored-by: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com>
2026-08-14 21:35:30 -07:00
..