install.sh: --uninstall takes the mimeapps.list xdg-mime made when nothing else is in it

After 305c624ed a curl-piped install and --uninstall in a fresh HOME
left ~/.config/mimeapps.list holding only the "[Default Applications]"
header xdg-mime wrote at install. A list with no entry left (only
section headers and blank lines) now goes; one with any line of the
user's stays as it is, less magpie's.

Run at 305c624ed + this: node --test site/install.test.mjs
worker.test.mjs stable.test.mjs on mote (53 pass); install.test.mjs in
WSL magpie-desktop (14 pass); dash -n ok. Real run in WSL with the real
0.1.2345 release, sandbox HOME: with a text/html line of the user's the
list keeps it, and the rest of the run is as 305c624ed says.

Broken by hand: the rm taken out turns the --uninstall and --purge
tests red (the list is still there).

Not tried: a mimeapps.list with comments only (a # line counts as an
entry and keeps the file).
This commit is contained in:
yetone
2026-10-31 16:13:55 +08:00
parent 305c624eda
commit 90518de261
2 changed files with 8 additions and 1 deletions
+6 -1
View File
@@ -211,6 +211,11 @@ test("--uninstall takes off the command, menu entry, icon and magpie:// default,
assert.equal(u.status, 0, u.stderr);
for (const p of [r.exe, r.entry, r.icon]) assert.equal(existsSync(p), false, p);
assert.equal(readFileSync(r.mime, "utf8"), "[Default Applications]\ntext/html=firefox.desktop\n");
// with no line of the user's, the list xdg-mime made goes with it
const bare = installedDesktop(t);
const bu = bare.run(["--uninstall"]);
assert.equal(bu.status, 0, bu.stderr);
assert.equal(existsSync(bare.mime), false);
assert.ok(existsSync(r.settings), "the settings stay");
assert.equal(r.calls(), "", "magpie isn't asked to uninstall");
assert.equal(u.calls.length, 0, "nothing is downloaded");
@@ -260,7 +265,7 @@ test("--purge has magpie uninstall itself first, then takes off the install", (t
assert.match(r.calls(), /^uninstall --yes$/m);
for (const p of [r.exe, r.entry, r.icon, r.settings]) assert.equal(existsSync(p), false, p);
// magpie took the menu entry itself; its icon and magpie:// default go too
assert.doesNotMatch(readFileSync(r.mime, "utf8"), /magpie/);
assert.equal(existsSync(r.mime), false);
assert.doesNotMatch(u.stdout, /kept your settings/);
// magpie failing to: the command stays, to run it again
+2
View File
@@ -152,6 +152,8 @@ if [ -n "$uninstall" ]; then
if [ -f "$list" ] && grep -qx 'x-scheme-handler/magpie=magpie\.desktop;\{0,1\}' "$list"; then
grep -vx 'x-scheme-handler/magpie=magpie\.desktop;\{0,1\}' "$list" > "$list.magpie-new" || true
mv "$list.magpie-new" "$list"
# a list left with no entry at all (the one xdg-mime made) goes
grep -qv -e '^\[.*\]$' -e '^[[:space:]]*$' "$list" || rm -f "$list"
removed=1; say "removed magpie:// from $list"
fi
if [ -d "$apps" ] && ! ls "$apps" | grep -q '\.desktop$'; then