From 2ea64d06033559fecfb9800a302cd13adbfcfa1a Mon Sep 17 00:00:00 2001 From: Felitendo Date: Sun, 6 Sep 2026 13:58:11 +0200 Subject: [PATCH] fix: write the current answer into an entry the ledger forgot A desktop entry that was edited in place is left alone once it carries the marker, and the only thing that ever writes it again is the undo a change of flags goes through - which reads the ledger. So an entry the ledger has lost is one nothing looks at any more: it keeps whatever an older version put on its command line, and an update that moves browsers to a different flag moves every browser but that one. The copy taken before the edit is named after the path, not recorded in the ledger, and is still there. A marked entry with no ledger line is now put back from that copy and written again from scratch, which is the same thing the undo would have done, and it lands in the ledger on the way out. Only entries edited in place need this. A generated entry is built from the source entry every time and is right by construction, and a flag file has its block rewritten whenever the contents differ. --- src/lib/common.sh | 10 ++++++++++ src/lib/patch.sh | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lib/common.sh b/src/lib/common.sh index 570dfa2..b8f21e3 100644 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -293,6 +293,16 @@ mca_ledger_add() { printf '%s\t%s\t%s\n' "$kind" "$path" "$detail" >> "$MCA_LEDGER" } +# mca_ledger_has +# Whether the ledger still knows about that file. Worth asking because the copy +# kept beside it is named after the path and outlives a ledger that was lost or +# truncated: a file nothing has a record of any more is one nothing would ever +# look at again. +mca_ledger_has() { + [[ -f $MCA_LEDGER ]] || return 1 + awk -F'\t' -v p="$1" '$2 == p { found = 1 } END { exit !found }' "$MCA_LEDGER" +} + mca_ledger_forget() { local path="$1" tmp [[ -f $MCA_LEDGER ]] || return 0 diff --git a/src/lib/patch.sh b/src/lib/patch.sh index 11d8948..497d090 100644 --- a/src/lib/patch.sh +++ b/src/lib/patch.sh @@ -423,9 +423,21 @@ mca_desktop_apply() { # a shortcut to. _mca_entry_patch_inplace() { local file="$1" gate="$2" - local id prog packaging=native content backup kind + local id prog packaging=native content backup kind copy - grep -q "^$MCA_MARK_INPLACE=" "$file" 2>/dev/null && return 0 + # Already ours, and normally that is the end of it: what is in there is what + # this version put there. Not so for a file the ledger has no record of - + # nothing would ever look at that one again, neither the undo a change of + # flags goes through nor this, which leaves a marked file alone, and it would + # keep an answer from an older version for good. The copy taken before the + # edit is named after the path and is still there, so the file goes back to + # what it was and is written again below. + if grep -q "^$MCA_MARK_INPLACE=" "$file" 2>/dev/null; then + mca_ledger_has "$file" && return 0 + copy="$MCA_BACKUPDIR/$(mca_backup_name "$file")" + [[ -f $copy ]] || return 0 + cp -p -- "$copy" "$file" 2>/dev/null || return 0 + fi _mca_desktop_read "$file" [[ -n $DE_EXEC ]] || return 0