From fc063aba4822e8e7d9ccc6c721fc2a711298e166 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 1 Mar 2026 17:35:16 +0200 Subject: Extract generate::safe_overwrite helper to eliminate DRY violation The "safe overwrite" pattern (diff -q tmp dest, then rm or mv) was duplicated in template, gemfeed (2x), and notes modules. Extracted into a shared helper with unit tests covering all three cases (no dest, identical dest, differing dest). Co-Authored-By: Claude Opus 4.6 --- lib/template.source.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lib/template.source.sh') diff --git a/lib/template.source.sh b/lib/template.source.sh index 9488ea8..5d9f4dd 100644 --- a/lib/template.source.sh +++ b/lib/template.source.sh @@ -71,13 +71,7 @@ template::_generate_file () { template::_generate < "$tpl" > "$dest.tmp" # Only overwrite if content actually changed, preserving mtime for caches - if [[ -f "$dest" ]] && diff -q "$dest.tmp" "$dest" >/dev/null 2>&1; then - rm "$dest.tmp" - log VERBOSE "Template output unchanged for $dest" - else - mv "$dest.tmp" "$dest" - log INFO "Done generating $dest" - fi + generate::safe_overwrite "$dest.tmp" "$dest" cd - >/dev/null } -- cgit v1.2.3