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/notes.source.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'lib/notes.source.sh') diff --git a/lib/notes.source.sh b/lib/notes.source.sh index 85bd2b5..08af3e5 100644 --- a/lib/notes.source.sh +++ b/lib/notes.source.sh @@ -42,9 +42,5 @@ That were all notes. Hope they were useful! NOTES # Only overwrite if content changed, preserving mtime for template skip logic - if [[ -f "$notes_dir/index.gmi" ]] && diff -q "$notes_dir/index.gmi.tmp" "$notes_dir/index.gmi" >/dev/null 2>&1; then - rm "$notes_dir/index.gmi.tmp" - else - mv "$notes_dir/index.gmi.tmp" "$notes_dir/index.gmi" - fi + generate::safe_overwrite "$notes_dir/index.gmi.tmp" "$notes_dir/index.gmi" } -- cgit v1.2.3