diff --git a/src/manager.c b/src/manager.c index c093088..ec8dd44 100644 --- a/src/manager.c +++ b/src/manager.c @@ -74,7 +74,7 @@ typedef struct { #endif /* The version of this build, shown on the ABOUT page. The release workflow fails when its version input differs from this. */ #ifndef PM_VERSION -#define PM_VERSION "1.3.6" +#define PM_VERSION "1.3.7" #endif #define WORK "/tmp/openmpc-pm" #define MAXPKG 1024 /* cards kept: the catalog (272 plugins on 2026-11-17), then local zips and unregistered folders; what does not fit is logged */ @@ -2874,20 +2874,35 @@ static void prepare(mgr_t *m, pkg_t *q) { "SETTINGS='%s'; SNAP='" WORK "/snap'; RES='" WORK "/result'\nrm -rf \"$SNAP\"; mkdir -p \"$SNAP\"; : > \"$RES\"\n" /* item ID FOLDER cmd...: snapshot the plugin folder and MPC.settings, run cmd; on failure put both back and say why (DESIGN 7) */ "item() {\n id=$1; dir=$2; act=$3; ver=$4; shift 4; snap=''\n" - /* a small folder is copied to RAM (WORK); a big one to a hidden sibling on its own drive, after a free-space check */ + /* a safety copy an earlier apply left (MPC power-cycled mid-copy, plugin-manager #46). Only a copy marked complete + * (.done) is ever put back, and only when the plugin folder is gone; with the folder there it is just removed */ + " if [ -n \"$dir\" ]; then old=\"$(dirname \"$dir\")/.pm-snap-$id\"\n" + " if [ -e \"$old\" ] && [ -d \"$dir\" ]; then rm -rf \"$old\" \"$old.done\"; echo \"removed the safety copy an earlier update left at $old\"\n" + " elif [ -e \"$old\" ] && [ -f \"$old.done\" ]; then mv \"$old\" \"$dir\" && rm -f \"$old.done\" && echo \"put $dir back from the safety copy an earlier update left\"\n" + " elif [ -e \"$old\" ]; then echo \"$id|fail|an earlier update was cut off and left an incomplete safety copy at $old\" >> \"$RES\"; return 1; fi\n" + " fi\n" + /* a small folder is copied to RAM (WORK); a big one to a hidden sibling on its own drive, after a free-space check. + * On its own drive the installer's staged copy needs as much room again, so twice the folder (plus 64 MB) must be free */ " if [ -n \"$dir\" ] && [ -d \"$dir\" ]; then\n" " sz=$(du -sk \"$dir\" 2>/dev/null | cut -f1); sz=${sz:-0}\n" - " if [ \"$sz\" -le \"${PM_SNAP_KB:-49152}\" ]; then snap=\"$SNAP/$id.dir\"; else snap=\"$(dirname \"$dir\")/.pm-snap-$id\"; fi\n" - " if [ -e \"$snap\" ]; then echo \"$id|fail|an earlier update left a safety copy at $snap\" >> \"$RES\"; return 1; fi\n" + " if [ \"$sz\" -le \"${PM_SNAP_KB:-49152}\" ]; then snap=\"$SNAP/$id.dir\"; need=$((sz + 65536)); else snap=\"$(dirname \"$dir\")/.pm-snap-$id\"; need=$((2 * sz + 65536)); fi\n" " free=$(df -Pk \"$(dirname \"$snap\")\" 2>/dev/null | awk 'NR==2 {print $4}')\n" - " if [ \"${free:-0}\" -lt $((sz + 65536)) ]; then echo \"$id|fail|not enough free space to keep a safe copy\" >> \"$RES\"; return 1; fi\n" - " cp -a \"$dir\" \"$snap\" || { rm -rf \"$snap\"; echo \"$id|fail|could not keep a safe copy\" >> \"$RES\"; return 1; }\n" + " if [ \"${free:-0}\" -lt $need ]; then echo \"$id|fail|not enough free space to keep a safe copy\" >> \"$RES\"; return 1; fi\n" + " echo \"-- safety copy of $dir ($((sz / 1024)) MB), MPC starts again when the update is done\"\n" + " cp -a \"$dir\" \"$snap\" && : > \"$snap.done\" || { rm -rf \"$snap\" \"$snap.done\"; echo \"$id|fail|could not keep a safe copy\" >> \"$RES\"; return 1; }\n" " fi\n" " cp -p \"$SETTINGS\" \"$SNAP/$id.settings\" 2>/dev/null\n" " out=$(\"$@\" 2>&1); rc=$?\n pidof MPC >/dev/null && quiesce # an installer without -n started MPC again: MPC starts once, at the end\n" - " if [ $rc -eq 0 ]; then echo \"$out\"; echo \"$id|ok|$act $ver\" >> \"$RES\"; [ -n \"$snap\" ] && rm -rf \"$snap\"; rm -f \"$SNAP/$id.settings\"; return 0; fi\n" + " if [ $rc -eq 0 ]; then echo \"$out\"; echo \"$id|ok|$act $ver\" >> \"$RES\"; [ -n \"$snap\" ] && rm -rf \"$snap\" \"$snap.done\"; rm -f \"$SNAP/$id.settings\"; return 0; fi\n" " echo \"$out\"\n" - " if [ -n \"$dir\" ]; then rm -rf \"$dir\"; [ -n \"$snap\" ] && [ -d \"$snap\" ] && cp -a \"$snap\" \"$dir\" && rm -rf \"$snap\"; fi\n" + /* roll back: the failed folder is moved aside (not deleted) until the safety copy is back in its place */ + " if [ -n \"$snap\" ] && [ -f \"$snap.done\" ]; then\n" + " bad=\"$(dirname \"$dir\")/.pm-failed-$id\"; rm -rf \"$bad\"; [ -e \"$dir\" ] && mv \"$dir\" \"$bad\"\n" + " case $snap in \"$SNAP\"/*) cp -a \"$snap\" \"$dir\" ;; *) mv \"$snap\" \"$dir\" ;; esac\n" + " if [ $? -eq 0 ]; then rm -rf \"$bad\" \"$snap\" \"$snap.done\"\n" + " else rm -rf \"$dir\"; [ -e \"$bad\" ] && mv \"$bad\" \"$dir\"; echo \"-- $id: could not put the old folder back; the safety copy stays at $snap\"; fi\n" + " elif [ -n \"$dir\" ] && [ -z \"$snap\" ]; then rm -rf \"$dir\" # a new install: nothing was there before\n" + " fi\n" " [ -f \"$SNAP/$id.settings\" ] && cp -p \"$SNAP/$id.settings\" \"$SETTINGS\"\n" " echo \"$id|fail|$(echo \"$out\" | tail -n 1 | tr '|' ' ')\" >> \"$RES\"; echo \"-- $id failed: rolled back\"; return 1\n}\n", m->dev->state, m->dev->settings); @@ -2987,10 +3002,13 @@ static void prepare(mgr_t *m, pkg_t *q) { else if (is_addin(p)) fprintf(f, "echo '-- remove %s'\nitem '%s' '%s' remove '' sh '%s/uninstall.sh' -y -n -t '%s'\n", p->id, p->id, dq, synths, synths); else if (p->queued == Q_INSTALL) { - fprintf(f, "echo '-- install %s %s'\nitem '%s' '%s' install '%s' sh '%s/install.sh' -y $(batch '%s/install.sh') -t '%s' && setstate '%s' '%s' && rm -rf '" WORK "/%s' '" WORK "/%s.zip'\n", - p->id, p->latest, p->id, dq, p->latest, p->dir, p->dir, synths, p->id, p->latest, p->id, p->id); - if (m->dev->vst2 == 2 && dq[0]) /* the installer writes plugin-meta.xml; MPC 3.10.1 needs plugin.json beside it */ - fprintf(f, "[ -d '%s' ] && sh '" WORK "/vst2.sh' --json '%s'\n", dq, dq); + /* MPC 3.10.1 needs a plugin.json beside the plugin-meta.xml an older installer writes: written only after the install + * succeeded (a failed one is rolled back and keeps the plugin.json it had, plugin-manager #46) */ + int js = m->dev->vst2 == 2 && dq[0]; + fprintf(f, "echo '-- install %s %s'\nif item '%s' '%s' install '%s' sh '%s/install.sh' -y $(batch '%s/install.sh') -t '%s'; then\n" + " setstate '%s' '%s'; rm -rf '" WORK "/%s' '" WORK "/%s.zip'\n%s%s%s%s%sfi\n", + p->id, p->latest, p->id, dq, p->latest, p->dir, p->dir, synths, p->id, p->latest, p->id, p->id, + js ? " [ -d '" : "", js ? dq : "", js ? "' ] && sh '" WORK "/vst2.sh' --json '" : "", js ? dq : "", js ? "'\n" : ""); } else { fprintf(f, "echo '-- remove %s'\nitem '%s' '%s' remove '' sh '%s/uninstall.sh' -y $(batch '%s/uninstall.sh') -t '%s' && setstate '%s' '' && rm -rf '" WORK "/%s' '" WORK "/%s.zip'\n", p->id, p->id, dq, p->dir, p->dir, synths, p->id, p->id, p->id); diff --git a/src/vst2_migrate_sh.h b/src/vst2_migrate_sh.h index c1cbbb9..f706063 100644 --- a/src/vst2_migrate_sh.h +++ b/src/vst2_migrate_sh.h @@ -118,9 +118,16 @@ static const char VST2_MIGRATE_SH[] = "\n" "if [ -n \"$JSON\" ]; then\n" " d=${JSON%/}\n" + " # a plugin.json whose binary for this CPU is in the folder (the one the package ships) is kept as it is: it can name binaries\n" + " # (a universal zip's \"-arm32.so\"/\"-arm64.so\") that plugin-meta.xml or an old MPC.settings entry do not (plugin-manager #46)\n" + " have=$(sed -n \"s/.*\\\"$KEY\\\": *\\\"\\([^\\\"]*\\)\\\".*/\\1/p\" \"$ROOT$d/plugin.json\" 2>/dev/null | head -n 1)\n" + " if [ -n \"$have\" ] && [ -f \"$ROOT$d/$have\" ]; then echo \"kept $d/plugin.json ($KEY $have is in the folder)\"; retire_old_skins \"${d##*/}\" \"${d%/*}\"; exit 0; fi\n" " el=$(element \"$ROOT$d\" \"${d%/*}\")\n" " [ -n \"$el\" ] || { echo \"$d: no plugin-meta.xml and no MPC.settings entry\" >&2; exit 1; }\n" " uid=$(attr uid \"$el\"); case $uid in *[!0-9a-fA-F]*|'') echo \"$d: uid \\\"$uid\\\" is not hex\" >&2; exit 1 ;; esac\n" + " so=$(relfile \"$ROOT$d\" \"$(attr file \"$el\")\")\n" + " # never name a binary that is not there: MPC would drop the plugin from its list. Whatever plugin.json there is stays.\n" + " [ -f \"$ROOT$d/$so\" ] || { echo \"$d: binary $so is not in the folder; plugin.json left as it was\" >&2; exit 1; }\n" " write_json \"$ROOT$d/plugin.json\" \"$el\" && echo \"wrote $d/plugin.json\" || exit 1\n" " retire_old_skins \"${d##*/}\" \"${d%/*}\"\n" " exit 0\n" diff --git a/tests/run.sh b/tests/run.sh index 6c08521..b48f692 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -128,9 +128,17 @@ grep -q "apply_state 3" /tmp/vst2.out grep -qF "APPLY copies your 1 installed plugin there" /tmp/vst2.out A=/tmp/openmpc-pm/apply.sh grep -qF "echo '"'"'-- move to VST2 Plugins'"'"'" $A -[ "$(grep -n "move to VST2" $A | cut -d: -f1)" -lt "$(grep -n "^item " $A | head -n 1 | cut -d: -f1)" ] # the move runs before any install +[ "$(grep -n "move to VST2" $A | cut -d: -f1)" -lt "$(grep -nE "^(if )?item " $A | head -n 1 | cut -d: -f1)" ] # the move runs before any install grep -qF -- "-t '"'"'/nvme/VST2 Plugins'"'"'" $A grep -qF -- "--json '"'"'/nvme/VST2 Plugins/" $A +grep -B2 -- "--json '"'"'/nvme/VST2 Plugins/" $A | grep -q "^if item " # plugin.json only after a successful install (#46) +# #46: a plugin.json whose binary is in the folder (a universal zip: -arm32/-arm64 names) is kept; one naming a missing binary is never written +U="/nvme/VST2 Plugins/acme - VST - Uni"; mkdir -p "$U"; : > "$U/uni-arm64.so" +printf '"'"'{"name": "Uni", "uid": "0x556e6931", "file32": "uni-arm32.so", "file64": "uni-arm64.so"}\n'"'"' > "$U/plugin.json"; cp "$U/plugin.json" /tmp/uni.json +printf '"'"'\n'"'"' > "$U/plugin-meta.xml" +ARCH=aarch64 sh /tmp/openmpc-pm/vst2.sh --json "$U" | grep -qF "kept $U/plugin.json"; cmp -s "$U/plugin.json" /tmp/uni.json +rm -f "$U/uni-arm64.so"; ! ARCH=aarch64 sh /tmp/openmpc-pm/vst2.sh --json "$U" 2>/tmp/uni.err; grep -qF "binary uni.so is not in the folder" /tmp/uni.err; cmp -s "$U/plugin.json" /tmp/uni.json +rm -rf "$U" # run the move for real (MPC "stopped": systemctl is a stub) and check what MPC 3.10.1 would see mkdir -p "/nvme/Synths/acme - VST - Oldie/Plugin Skins" && echo old > "/nvme/Synths/acme - VST - Oldie/Plugin Skins/TUI.json" ARCH=aarch64 sh /tmp/openmpc-pm/vst2.sh --apply # the container is x86_64; this fake device is a Gen2 (pluginList-arm-64bit) @@ -430,9 +438,22 @@ PM_SNAP_KB=0 sh /tmp/openmpc-pm/apply.sh grep -q "^faily|fail|disk full" /tmp/openmpc-pm/result [ -f "$T/Faily dir/old" ] && [ ! -e "$T/Faily dir/partial" ] && [ ! -e "$T/.pm-snap-faily" ] || { echo "FAIL: the big-folder rollback"; exit 1; } rm -rf /tmp/openmpc-pm; /tmp/drive_addins one Faily > /dev/null -mkdir -p "$T/Faily dir/x"; mkdir -p "$T/.pm-snap-faily" +# #46: a safety copy an earlier update left (cut off by a power cycle) never blocks: with the folder there it is removed and the update runs +mkdir -p "$T/Faily dir"; echo old > "$T/Faily dir/old"; mkdir -p "$T/.pm-snap-faily"; echo partial > "$T/.pm-snap-faily/half" PM_SNAP_KB=0 sh /tmp/openmpc-pm/apply.sh -grep -q "^faily|fail|an earlier update left a safety copy" /tmp/openmpc-pm/result +grep -q "^faily|fail|disk full" /tmp/openmpc-pm/result || { cat /tmp/openmpc-pm/result; exit 1; } +grep -qF "removed the safety copy an earlier update left" /tmp/openmpc-pm/apply.log +[ -f "$T/Faily dir/old" ] && [ ! -e "$T/Faily dir/half" ] && [ ! -e "$T/.pm-snap-faily" ] && [ ! -e "$T/.pm-snap-faily.done" ] || { echo "FAIL: leftover safety copy"; exit 1; } +# the folder gone and a complete copy left (.done): put back, then updated as usual +rm -rf /tmp/openmpc-pm; /tmp/drive_addins one Faily > /dev/null +mv "$T/Faily dir" "$T/.pm-snap-faily"; : > "$T/.pm-snap-faily.done" +PM_SNAP_KB=0 sh /tmp/openmpc-pm/apply.sh +grep -qF "back from the safety copy an earlier update left" /tmp/openmpc-pm/apply.log && [ -f "$T/Faily dir/old" ] && [ ! -e "$T/.pm-snap-faily" ] || { echo "FAIL: complete safety copy not put back"; exit 1; } +# the folder gone and an incomplete copy: nothing is guessed, the copy stays for the user +rm -rf /tmp/openmpc-pm; /tmp/drive_addins one Faily > /dev/null +mv "$T/Faily dir" "$T/.pm-snap-faily" +PM_SNAP_KB=0 sh /tmp/openmpc-pm/apply.sh +grep -q "^faily|fail|an earlier update was cut off and left an incomplete safety copy" /tmp/openmpc-pm/result && [ -f "$T/.pm-snap-faily/old" ] || { echo "FAIL: incomplete safety copy"; exit 1; } rm -rf "$T/.pm-snap-faily" "$T/Faily dir" rm -rf /tmp/openmpc-pm; /tmp/drive_addins one Faily > /dev/null mkdir -p "$T/Faily dir"; echo old > "$T/Faily dir/old"; cp "$T/Faily dir/old" /tmp/old.keep