Installable (the Windows install-location dialog's check) walked up from
the chosen folder to the first one exists() said was there, and removed
the topmost one below it with os.RemoveAll. exists() was os.Stat == nil,
so a folder whose Stat failed for any other reason than "not there"
(access denied, a share that doesn't answer) counted as one the check
had made, and was removed with everything in it, up to a drive root.
Now:
- present(p) tells "there", "not there" (fs.ErrNotExist only) and
unknown apart; statPath is os.Stat, swapped by tests.
- Installable refuses with "can't tell whether X is there" when any
folder on the way is unknown, before making anything. It makes the
missing folders one by one with os.Mkdir, records only those it made
(one made by someone else meanwhile, ErrExist, isn't recorded), and
removes them deepest first with os.Remove, so nothing it didn't make,
and no folder that got content, is removed.
- settle's "is magpie.exe there" before installFresh (which renames
over to) refuses too when the answer is unknown; the download runs on.
- The other exists() callers were checked: RemoveStaleNew skips a
staged file it can't look at, writeCom moves a magpie.com aside only
when it is seen there, keepWebView only writes a note, installed()
and EnsureCompanion remove nothing. Unknown already meant "leave it"
there, so they keep exists().
Tests (internal/update/install_unknown_test.go): a Stat that answers
permission denied for an existing ancestor holding a file, for the
chosen folder itself holding a file, and for an installed magpie.exe;
each asserts the folder and file survive (checked before the error).
Plus folders made are removed while existing ones with files stay, and
present's three answers.
Run at this tree (parent 80ccaba64):
- mote-run go test -count=1 -timeout 45m ./internal/update ./internal/gui:
ok update 141s, ok gui 261s.
- gofmt -l internal/: nothing.
- mote-run GOOS=windows go vet ./...: ok. GOOS=linux go vet ./... fails
in wails' linux files (cgo off when cross-compiling, the same at any
tree); GOOS=linux go vet -tags nogui ./... (the code standards' form):
ok. GOOS=windows go build: ok.
- win-run go test -count=1 ./internal/update on xiaomi-gpu: every test
passes but TestPackagedByDpkg, red the same on origin/main 80ccaba64
(its magpie:amd64.list fixture is an NTFS stream name), filed as #4603.
Broken by hand: Installable put back to the walk-up + RemoveAll and
settle back to !exists(to), with the injectable stat kept. All three
new tests went red: Tools/notes.txt and magpie/settings.json "is gone",
and magpie.exe held "MZ new download" instead of "MZ installed".
Restored, green.
Not tried: the real Windows dialog against an access-denied folder or a
dead network share (the permission error is injected); a folder getting
content between Mkdir and the cleanup (no hook there, os.Remove refusing
a non-empty folder is relied on); the full go test ./... suite.