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