CHENGJIAHEGOXIS on X, on v0.1.4241 (Windows): installing GoAnyAPI from
the Plugins page still failed with "Unexpected: failed copying files
from cache to destination for package @magpie-community/tools-goanyapi"
and "(LICENSE is missing)", at both of addDist's tries.
Cause, from Bun 1.4.4's source (src/install/PackageInstall.rs): on
Windows Bun copies each cached file by CreateHardLinkW, then CopyFileW,
with no other fallback; a Win32 error it has no errno for prints as
"Unexpected". On a machine where that copy fails (agency-agents failed
the same way there before) dropping the cache entry and trying again
can't help, which is all v0.1.4205 to v0.1.4241 did.
Now, when Bun's copy is still not whole after the second try, magpie
makes it from the tarball installDist verified against the index's
sha512 (unpackDist): the files go into a temp folder beside
node_modules/<name> with .bun-tag = the tarball's integrity, as Bun
writes it, and the folder is renamed into place. Bun takes a tarball
package whose .bun-tag matches as installed and never copies over it,
so bun add runs once more to write the dependency and bun.lock. Only a
package with no dependencies (optional, peer, bundled) whose
package.json names it is made this way; a path leaving the package is
refused. When magpie can't make it either, the add is errDistPartial as
before.
Run at c00c491bc + this change:
- mote: go test -count=1 ./internal/plugin/... ok (153s); go vet,
GOOS=windows go vet, GOOS=linux go vet -tags nogui ./internal/plugin/
clean; gofmt -l clean.
- xiaomi-gpu (Windows 11): go test -run
'TestDistAdd|TestUnpackDist|Leftover|Unnamed|TestDist' ./internal/plugin/ ok.
- Red on the old code: TestDistAddBunCantCopy against origin/main's
distcopy.go failed in both subtests with the reporter's error shape
("Unexpected: failed copying files … (package.json is missing)",
"(index.js is missing)").
- Real Bun 1.4.4, throwaway tests (not committed): on mote, a copy
unpacked with .bun-tag plus a MARK file survived bun add of another
package, bun install, bun update, bun remove of another, and bun
install with bun.lock deleted. On Windows, unpackDist then real
`bun add ./dist/<tgz>` wrote the dependency and lock, kept MARK, and
`bun install` said "no changes".
Not tried: the reporter's machine and its exact Win32 code; I could not
make real Bun's cache copy fail on Windows (a denied read is got past by
the hardlink, and across volumes Bun re-extracted its entry), so the
fallback itself ran with the fake bun only. A dist package with
dependencies is not unpacked, and the npm add is not covered.