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.
nianshou5 on Discord (#help, Windows): magpie.com and magpie.exe.new
showed on the Desktop and came back after being deleted. Both were
written beside magpie.exe:
- magpie.exe.new is the update the GUI downloads as soon as it is out
and swaps in at the next restart. StageBinary put it beside the
program whenever that folder was writable, so it sat on the Desktop
until a restart, and a deleted one was downloaded again by the next
check.
- magpie.com (#3737) is written at every start while the app's folder
is on PATH, and Settings > Command line's Add puts that folder on
PATH, so deleting it on the Desktop lasted until the next start.
Now:
- StageBinary downloads into magpie's cache, in a folder of this
program's own (update/<hash of the exe path>), when a rename from
there reaches the program's folder (renamesInto, a real probe: the
swap must stay one rename on one volume). With the cache on another
volume it goes into a hidden .magpie-update folder beside the program
(FILE_ATTRIBUTE_HIDDEN on Windows). A folder magpie may not write is
unchanged (cache, moved in as administrator). The stage folder is
removed after the swap or a failed download.
- At start RemoveStaleNew looks in every place a download may be,
magpie.exe.new beside the program included, and removes one no newer
than the running version (same bytes, or an older file version); a
newer one stays, as before.
- Settled (the installed copy opened from a Desktop/Downloads one)
also removes the update downloaded for that one, which nothing will
put in now.
- In a download folder (Desktop, Downloads, a temp folder, as
isDownloadFolder already says) a start only keeps an existing
magpie.com up to date and never writes a missing one; Add still
writes it. Any other folder on PATH is as before. A Desktop
magpie.exe that opens the installed one (Settle) already wrote none.
Run:
- Windows (win-run, xiaomi-gpu, sandbox HOME from testenv), a repro
test with the running test binary standing for magpie.exe on a
Desktop on PATH: at origin/main 72ed121fd StageBinary staged
test.test.exe.new beside it, and magpie.com came back after delete +
start; with this change the download was in
AppData\Local\magpie\update\<hash>\ and magpie.com stayed gone.
- Windows: a real program (whoami.exe) staged into the cache passed the
real trial start (canStart) and was swapped in for a Desktop
magpie.exe with the real moveAside/moveIn; the stage folder was gone
after.
- At the pushed head (rebased on d6beb9975): go test ./internal/update
on mote and on Windows: ok. Before the rebase also on Linux (wsl-run). gofmt, go vet ./internal/update (darwin, linux, windows),
GOOS=windows go vet ./internal/gui ./internal/cli: clean.
- go test ./internal/gui ./internal/cli on Windows: TestUpdateThatWontStart,
TestLodyImportHandoff, TestImportStatusUnreadableIsUnknown,
TestAionUiImportRow (#4115), TestGatewayHeldByAContainer (#2107,
#3649) and TestLibraryMCPHub (#4140) red, the same 6 when run at
origin/main 72ed121fd.
- Full suite on mote (-timeout 45m): started at the pre-rebase tree
(same update changes, base 72ed121fd) and still running at push; its
result and any red go in a follow-up.
Broken by hand: staging back beside the exe, the download-folder rule
in EnsureCompanion off, removeStaged out of Settled: the new tests
(TestUpdateStagedOutOfTheProgramsFolder, TestUpdateStagedHiddenWithoutTheCache,
TestStartClearsAnOlderDownloadBeside, TestNoCompanionPutBackOnTheDesktop,
TestSettledClearsOnlyMagpiesFiles, TestNoCompanionBesideAForwardingDownload)
went red.
Not tried: a real GUI self-update of a release build on the Windows
desktop, a cache and Desktop on separate real volumes (the hidden
fallback was tested with no cache), the reporter's own machine, and a
real terminal's `magpie` (unchanged code outside download folders).
lucky_eagle_38 on Discord: Windows magpie is one exe that lands in
Downloads, the user moves it around, and the `magpie` command came from
a magpie.com ("ms-dos" file) magpie wrote beside it there. They asked
for a fixed install folder, with the command coming from PATH.
Before: wherever the exe ran, the Start menu Magpie.lnk, App Paths,
Open at login (HKCU Run "magpie") and updates named it there. Settings >
Command line put that folder on the user PATH and wrote magpie.com (or
magpie.cmd) beside it, and EnsureCompanion kept writing magpie.com there.
Now (update.Settle, first thing in gui.Run): the desktop app run from
Downloads, the Desktop or a temp folder (an exe opened inside a zip)
copies itself to %LOCALAPPDATA%\Programs\magpie\magpie.exe, per-user and
with no admin. It puts that folder first on the HKCU PATH with its
magpie.com (cliPlace, with WM_SETTINGCHANGE as before) and opens the
copy (Forward waits for its MAGPIE_STARTED, then passes that on, so an
update restart waiting on the download isn't rolled back). The copy's
shortcut.Ensure re-points the Start menu lnk and App Paths. Its updates
replace the installed exe in place. The download quits.
- Run again: the download opens the installed copy. If its RT_VERSION
is newer than the installed one, it first goes in place of that copy
(InstallBinaryAside, as an update does). An older or unversioned
download never replaces it.
- Open at login: the Run value is re-pointed only when it named the
download (autostart.Repoint). Task Manager's StartupApproved off flag
is kept.
- Leftovers beside the download (update.Settled, in the installed copy):
- Removed: what updates moved aside (.old). Also magpie.com and
magpie.cmd, but only when magpie wrote them for that exe (comRuns
and shimRuns check the marker and target).
- Never removed: the download itself and any other file.
- EnsureCompanion writes no magpie.com beside a download that forwards.
- WebView2's profile is keyed by exe name. The old profile
(%APPDATA%\magpie-windows-amd64.exe) is kept through a webview-profile
note beside the install, which appdir.WebView reads. magpie uninstall
removes that noted profile too (only a folder directly in %APPDATA%
with an EBWebView in it).
Not moved:
- an exe in a folder the user chose (D:\Tools, a USB drive, the home
folder, Documents, a subfolder of Downloads);
- a portable copy (a data folder or .portable beside it);
- any copy run with MAGPIE_NO_INSTALL=1;
- CLI runs (only the desktop app installs).
Left for old users: the Downloads entry an earlier Command line put on
the HKCU PATH stays. The user may have added it themselves, and it now
comes after the install folder. Taskbar pins still name the download,
which opens the installed copy.
Run:
- Real run on xiaomi-gpu (Windows 11) as a throwaway local user,
through a scheduled task (the user is deleted now; its profile hive
was still held at cleanup and is removed on the next unload):
- Seeded with the real v0.1.2124 in Downloads, its folder on PATH, its
magpie.com, a Run value with the off flag, the lnk and App Paths on
it, a .old, a user's own magpie.cmd and notes.txt.
- Then ran release-built (make release-windows) v0.1.2000 from
Downloads with `tray`:
- Programs\magpie got magpie.exe 0.1.2000, magpie.com and the note.
- PATH is that folder first.
- Run, lnk and App Paths now name it. The off flag is kept.
- Downloads lost magpie.com and the .old and kept the exe, the
user's magpie.cmd and notes.txt.
- The download exited 0, and the installed copy ran.
- Again: forwarded, nothing changed.
- v0.1.2001 from Downloads: it replaced the installed 0.1.2000.
- The registry PATH's `magpie` is Programs\magpie\magpie.com, and
`magpie version` gives v0.1.2001.
- Ran a copy at ~\Tools\magpie.exe: it ran there and the install was
not touched.
- The installed copy's `magpie update` went to the real v0.1.2126
in place (magpie.exe.old aside).
- win-run (Windows): go test ./internal/update ./internal/autostart
./internal/appdir ./internal/shortcut ok. ./internal/gui has 5 reds:
TestGatewayHeldByAContainer, TestLodyImportHandoff,
TestImportStatusUnreadableIsUnknown, TestAionUiImportRow and
TestUpdateThatWontStart. They fail the same alone on origin/main
4a4a90c23 and are filed in #4115.
- mote: go vet ./..., GOOS=windows go vet ./..., GOOS=linux go vet
-tags nogui ./... and GOOS=windows go build all OK. go test -tags
nogui -timeout 45m ./... gives 80 ok, no FAIL, at 9e8c22dad + this.
After rebasing onto fce294c5a (gui assets, pii, sessions, WorkBuddy
min), the vets and the gui, uninstall, update and sessions packages
ran again on mote: all ok. On Windows, uninstall, update, autostart
and appdir ran ok at that head. TestCoreScriptBudget was red at
6db21d869, the upstream head then, and fce294c5a fixed it.
- Broken by hand on Windows, each one red:
- no forwards check in EnsureCompanion:
TestNoCompanionBesideAForwardingDownload;
- always replace: TestSettleKeepsTheInstalledVersion;
- the shim always removed: TestSettledClearsOnlyMagpiesFiles;
- no download-folder check: TestSettleLeavesAChosenPlace;
- the original marker passed on: TestForwardWaitsForTheInstalledOne;
- no keepWebView: TestSettleKeepsTheWebViewProfile;
- a case-sensitive Run path: TestRepointed;
- uninstall without the noted profile: TestProfilesTakeTheNotedOne.
Not tried:
- the GUI on an interactive desktop: the real run was in a batch logon,
where WebView2 did start;
- a OneDrive-moved Downloads (it is read from the known folder);
- an exe opened from inside a zip;
- taskbar pins.
Not changed: magpie uninstall still leaves the exe, magpie.com and the
PATH entry, now in Programs\magpie. #2663 is open for the uninstall
flow that cleans them.
lucky_eagle_38410 on Discord (#general, 10-28): every run of the command
line wrote a new magpie.com. magpie.com is the console launcher from
2afacd7d1 (#3737): PowerShell and cmd run magpie.com before magpie.exe
(PATHEXT), and wait for it, so a prompt, a password and the exit code
reach the terminal; the GUI-linked magpie.exe alone gives the prompt back
at once. It is needed, and writeCom already writes it only when its bytes
differ.
They differed on every release. `make release-windows` built the
launcher from the git checkout with Go's default -buildvcs, which stamps
vcs.revision and vcs.time into the binary, so each release carried a
different magpie.com though the launcher's source hadn't changed, and the
first `magpie` after each update (several a day) wrote it again, moving a
running one aside as magpie.com.old. The launcher is now built with
-buildvcs=false, so magpie.com changes only when the launcher does.
Run:
- Windows box (xiaomi-gpu, PowerShell 5.1 over a ConPTY, sandbox
USERPROFILE/APPDATA, a folder of its own on PATH), the app run as
magpie.exe, then through magpie.com, then the next version copied over
magpie.exe and run again:
- real releases v0.1.1861 -> v0.1.1862: magpie.com 5F55B8D4... ->
2E6AD7D9..., rewritten on the update.
- make release-windows at origin/main 6e080ca04, at two commits of the
same tree: B26668C1... -> 15AD7512..., rewritten.
- make release-windows with this change, the same two commits:
782517C6... both times, mtime unchanged.
- mote: go test -tags nogui ./internal/update/...: ok. GOOS=windows and
GOOS=linux go vet ./internal/update/: ok. gofmt -l: clean.
- win-run: TestLauncherSameAtEveryCommit, TestWriteCom, TestComOwner,
TestEnsureCompanion, TestFindCLIPrefersCom pass on Windows.
Broken by hand: the Makefile without -buildvcs=false makes
TestLauncherSameAtEveryCommit red ("the launcher built at the next
commit differs ([-trimpath -ldflags=-s -w])"). The test builds a
program with the Makefile's launcher flags in a scratch git repo at two
commits and compares the bytes.
Not tried:
- A real release build in magpie-releases; the next tag is the first.
The first update to it still writes magpie.com once (its bytes change
from the stamped one); after that only a launcher change does.
- The arm64 build on a real ARM machine.
- The full go test ./...; only internal/update changed (a Makefile flag,
a comment and a test).
The Windows app is linked with -H windowsgui so a double click opens no
console, and PowerShell and cmd don't wait for a GUI program. The prompt
came back before magpie printed, and `magpie plugin login`'s password
keys went to the shell as well as to magpie (tom047784 / TomXPRIME on
Discord, 10-27; the handle error in the same report was 9298d2a).
A shell looks for `magpie` by PATHEXT, which lists .COM before .EXE. So
magpie now writes magpie.com beside the app. It is a 1.9MB console program
(internal/update/launcher), built and embedded by `make release-windows`
(the comlauncher tag). The shell waits for it. It runs the app with its own
std handles, passes MAGPIE_COM=1, waits, and exits with the app's code. The
app keeps those handles and borrows the console for the streams Windows
dropped (a GUI child gets no console handles), so redirection, pipes and
hidden prompts work. A command that opens the window (none, app, gui, tray,
panel, -Embedding, magpie: links) is started DETACHED, and the shell isn't
held. A double click and the Start menu still open magpie.exe.
Why this, and not a console-subsystem copy or a magpie-cli.exe: the
running process is still magpie.exe, so autostart, shortcuts, relaunch and
every os.Executable() use are unchanged. There is no new release asset (still
16), and magpie-releases needs no change. The trailer names the app, so a
download kept as magpie-windows-amd64.exe is run by its own name.
Where it is written:
- Settings › Command line's Add (cliPlace) writes it instead of magpie.cmd
in a build that carries it.
- A terminal command run as magpie.exe writes it when the folder is on PATH
or has a magpie.com or magpie.cmd, so existing users get it on their next
`magpie <cmd>`.
- The app's start (placeExe) writes it again when the bytes differ, so an
update brings it along.
- A running magpie.com is moved aside and cleared on the next run.
- A copy beside a magpie.exe leaves `magpie` to it (comOwner).
- The Command line row reads magpie.com as this app, with "(which runs
magpie.exe)".
Run, at 2e165fe9d (main since then touches none of these files):
- gofmt -l: clean
- go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...
- go build for darwin, linux -tags nogui and windows
- make release-windows: amd64 and arm64 are PE subsystem 2 (GUI), as before
- go test -tags nogui -count=1 -timeout 45m ./internal/update/...
./internal/cli/ ./internal/gui/ ./internal/proc/: all ok
- cli-path.test.cjs in chromium and webkit (11 + 11 pass); i18n-keys,
gui-zh-tw, gui-ja, gui-de pass
- The Windows box, with GOOS=windows test binaries: launcher's TestArgsOf,
TestOpensWindow and TestTargetName pass; update's TestWriteCom,
TestComOwner, TestEnsureCompanion, TestFindCLIPrefersCom and
TestCLIShim pass. TestComMagicIsTheLaunchers reads the source, so it
can't run from a copied binary there; it passes on macOS.
- The Windows box, sandbox HOME, release build, interactive ConPTY over
ssh -tt with typed keys:
- Old v0.1.1675 in PowerShell 7.5.4: the prompt comes back before
"magpie 0.1.1675", $LASTEXITCODE is empty, `> out.txt` is empty, and
backup's passphrase is split between the shell and magpie.
- New build in PowerShell 7.5.4: the first `magpie` as magpie.exe wrote
magpie.com, and Get-Command then resolves it. `magpie version` prints
before the next line, with exit 0. A bad command gives 1. `> out.txt`
holds the version. backup reads "Passphrase for the backup:" and
"Again:" typed. restore reads "Passphrase:" typed. A piped passphrase
is read (wrong passphrase, exit 1).
- New build in cmd: `where` lists magpie.com first. The same version,
ERRORLEVEL 0 and 1, and typed backup and restore passphrases work.
Ctrl+C at a prompt ends it with 0xC000013A and leaves no magpie.exe.
- The update: an older magpie.com in place was moved aside and rewritten
by the first command of the new build, and the .old was gone after the
next one.
Broken by hand, red:
- writeCom always rewriting: TestWriteCom
- EnsureCompanion ignoring PATH: TestEnsureCompanion
- comOwner always true: TestComOwner
- app.js's old shim-only condition: the "magpie.com is said to run the app"
case in en and zh
Not tried:
- A real double click or the Start menu on the box. magpie.exe is still
GUI-subsystem and is what they open, but no window was opened there. The
sandbox app would share the gateway's port with the box's own magpie.
- Windows Terminal itself; the ConPTY ssh -tt gives is what it uses.
- The arm64 build on a real ARM machine.
- The full go test ./... at this head. Another session's agent and
gateway suite was running on the machine (load ~115), so only the
touched packages and internal/proc ran.