diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-01 17:35:16 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-01 17:35:16 +0200 |
| commit | fc063aba4822e8e7d9ccc6c721fc2a711298e166 (patch) | |
| tree | c42656f6db4fe10e1dc4ee8d585c974d7a323f82 /lib/template.source.sh | |
| parent | 00e5de525bde5d0d77d9553c6126908f2fdfde20 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'lib/template.source.sh')
| -rw-r--r-- | lib/template.source.sh | 8 |
1 files changed, 1 insertions, 7 deletions
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 } |
