forked from 1b-agent/opencadstudio-upstream
Installing a newer version of a plugin whose previous version is currently loaded failed on Windows. The marketplace writes the native library to the same filename, but a resident cdylib is memory-mapped by its runner process, so the overwrite is rejected with "being used by another process" (os error 32). Users hit this upgrading e.g. Land Survey 0.4.0 -> 0.4.4 and assumed a reboot was required. A loaded DLL can't be truncated or removed, but it *can* be renamed (the loader opens it with FILE_SHARE_DELETE). install() now moves every resident library in the package aside to a `.old` stash and writes the new one under its own name; the stash keeps serving the running session and the loader picks up the fresh library on the next start. Stale stashes are swept on the following upgrade, and this subsumes the previous differently-named-library cleanup. Adds regression tests, including one that reproduces the exact lock on Windows (FILE_SHARE_READ | FILE_SHARE_DELETE, no write share) and confirms an in-place overwrite fails while replace_library upgrades successfully. Co-Authored-By: Claude Opus 4.8 <[email protected]>