Commit Graph
2 Commits
Author SHA1 Message Date
yetone a69ffd9f01 appdir: a portable data folder in a moved Downloads, Desktop or Documents stays magpie's on update (jwaitq)
jwaitq on Discord (#feedback, 11-02): updated from v0.1.2630 to v0.1.2670
with the update button, and magpie showed the setup of long ago.

9f1734645 (v0.1.2648) added the folders the system keeps Downloads,
Desktop and Documents in (Windows' known folders, moved to D:\ or OneDrive;
the XDG ones on Linux, ~/下载) to sharedFolder. A data folder beside magpie
there was then judged as one in home\Downloads: passed over whenever the
installed folder (~/.config/magpie) holds magpie's files too. Every release
before took any data folder there, so a user who kept magpie portable in
such a folder had all their files in data\, and an installed folder from
long ago with a settings.json was enough to make the updated magpie read
that one instead. On Windows the updated exe, no longer portable and in a
download folder, then also installed itself to
%LOCALAPPDATA%\Programs\magpie (update.Settle) and opened that copy.

shared() now treats a moved folder (movedFolder, the system's folder that
isn't home's own) as before v0.1.2648 for a data folder holding magpie's
files: it is taken. One holding none of them (another app's, or emptied by
an archiver, tangle778's case) is still passed over. home's own Downloads,
Desktop, Documents, the home folder and /Applications are unchanged.
userFolder is a hook so the test runs on every system.

Users already hit: on Linux the next update finds data/ again by itself.
On Windows the copy in %LOCALAPPDATA%\Programs\magpie runs from a folder
with no data beside it, so it keeps reading %USERPROFILE%\.config\magpie;
their files are untouched in <moved Downloads>\data and are brought back by
hand (copy into .config\magpie, or a .portable file beside the old exe).
Anything set up in v0.1.2648..2670 went into .config\magpie.

Run at this head (b61121503 + this):
- mote (macOS): gofmt -l clean; go vet ./internal/appdir ./internal/update,
  GOOS=windows and GOOS=linux the same; go test -count=1 ./internal/appdir
  ./internal/update ./internal/settings ok.
- wsl-run (Ubuntu 24.04): go test ./internal/appdir ok.
- win-run (Windows 11): ./internal/appdir and ./internal/update: all pass
  but TestFoldersJoinedOnce (filed #4846) and TestPackagedByDpkg (#4603),
  both red the same on an unchanged b61121503 tree run there.

Broken by hand: shared() judging a moved folder as home's (the v0.1.2648
rule): TestResolveMovedDownloadsKeepsData red ("installed has old files:
\"\", want the data folder"; Passed names it).

Not tried: a real Downloads redirected on Windows, or a real update from
v0.1.2630 on such a layout; jwaitq's OS isn't known yet, and on a Mac
nothing about where data lives changed in v0.1.2630..2670.
2026-11-02 11:47:46 +08:00
yetone 9f1734645a appdir: exports go to the Downloads folder the system keeps, not home/Downloads
1Shin on Discord (#feedback, 11-02): an export (Settings' backup, a
request saved from the archive, a session as Markdown, the usage file)
joined $HOME/Downloads, which is wrong when Downloads was moved: Windows'
known folder (to another drive or OneDrive) or the XDG one on Linux
(~/下载 on a Chinese desktop).

appdir.UserFolder(kind) asks the system: SHGetKnownFolderPath
(FOLDERID_Downloads/Desktop/Documents, KF_FLAG_DONT_VERIFY) on Windows,
used when magpie's home is the profile Windows keeps it for (a home given
of its own, as a test's, keeps home\Downloads); $XDG_CONFIG_HOME/
user-dirs.dirs on Linux and the BSDs, read as xdg-user-dir does ("$HOME/x"
or "/x", quoted, backslash escapes, the last line wins); ~/Downloads on a
Mac. A failed lookup is home/kind, as before. gui's downloads() tries it,
then home/Downloads, then home. appdir's sharedFolder (a data folder
beside magpie there isn't portable data) adds the system's folders to
home's, and Cursor's AppImage is looked for in the system's Downloads too.
update's isDownloadFolder already asked Windows for its known folders and
is unchanged.

Run at this head (rebased on origin/main):
- mote (macOS): gofmt -l clean; go vet ./internal/appdir ./internal/gui
  ./internal/agent; GOOS=windows go vet of those and ./internal/update;
  GOOS=linux go vet -tags nogui of the three; go test ./internal/appdir ok,
  -run "Backup|Export|Archive" ./internal/gui ok, -run
  "Cursor|Desktop|Sandbox" ./internal/agent ok.
- wsl-run (Ubuntu 24.04): appdir's UserFolder/SharedFolder/ResolveDownloads
  tests and gui's TestExportGoesToTheSystemsDownloads,
  TestBackupLibraryRoundTrip and the session exports pass. Against the real
  xdg-user-dir in a sandbox HOME, "$HOME/下载", "/mnt/d/My Downloads" and
  "$HOME/a \"b\"" read the same; "$HOME/" gives home without the trailing
  slash.
- win-run (Windows 11): the appdir tests pass, and
  TestKnownFolderIsExplorers checks the known folder against Explorer's
  User Shell Folders value (read only). Windows expands that value's
  %USERPROFILE% once a process, with the first call's environment, so the
  check runs in a child of its own. The real profile gives
  C:\Users\yeton\Downloads, Desktop and Documents.

Broken by hand: no user-dirs.dirs read, or no profile check on Windows:
TestUserFolderXDG, XDGLines, XDGConfigHome and TestUserFolderWindows go
red. gui's downloads() without the system's folder:
TestExportGoesToTheSystemsDownloads red in WSL (saved in ~/Downloads, want
~/下载).

Not tried: a Downloads really redirected on Windows (to D:\ or OneDrive).
Moving it means writing the user's own User Shell Folders on the test box,
so the redirect is a faked known folder in TestUserFolderWindows only. Not
run: the GUI suite (no GUI file changed) and a full go test ./....
2026-11-02 05:19:45 +08:00