From: Svjatoslav Agejenko Date: Thu, 26 Nov 2026 22:21:59 +0000 (+0200) Subject: fix(docs): make the export cache actually skip unchanged pages X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=99117ca9519a3392de7c15b886230ed247dfa470;p=aukio.git fix(docs): make the export cache actually skip unchanged pages The state file was written by a redirection that attached to flock's group instead of the block, so every record went to stdout and the cache stayed empty; every run re-exported all nine pages. State reads and writes now go through state_lookup/state_record, which parse and emit real TAB-separated lines and replace only their own entry. Verified: first run exports 9, second run exports 0 and skips 9, editing one page exports exactly that page. --- diff --git a/Tools/Update web site b/Tools/Update web site index 3e3c3c4..3c3b349 100755 --- a/Tools/Update web site +++ b/Tools/Update web site @@ -3,6 +3,43 @@ cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -e "'$0' T"; exit; fi; cd .. +# State file format: one TAB-separated line per exported page, +# file +# Written only by this script; gitignored. A page is skipped when its recorded +# fingerprint equals the one just computed. +state_lookup() { + local wanted=$1 + local kind hash path + [ -f .org-export-state ] || return 0 + while IFS=$'\t' read -r kind hash path; do + if [ "$kind" = "file" ] && [ "$path" = "$wanted" ]; then + printf '%s' "$hash" + return 0 + fi + done < .org-export-state + return 0 +} + +state_record() { + local fingerprint=$1 + local org_file=$2 + local tmp=".org-export-state.tmp.$$" + exec 9>>.org-export-state.lock + flock 9 + { + if [ -f .org-export-state ]; then + while IFS=$'\t' read -r kind hash path; do + [ "$kind" = "file" ] || continue + [ "$path" = "$org_file" ] && continue + printf 'file\t%s\t%s\n' "$hash" "$path" + done < .org-export-state + fi + printf 'file\t%s\t%s\n' "$fingerprint" "$org_file" + } > "$tmp" + mv "$tmp" .org-export-state + exec 9>&- +} + # Incremental org -> html export. A page is re-exported only when its .org file # (or a first-level #+INCLUDE target) changed, or when its .html is missing. # The cache is .org-export-state in the repo root, gitignored. @@ -34,8 +71,9 @@ export_org_to_html() { ) local recorded="" - [ -f .org-export-state ] && \ - recorded=$(awk -F'\t' -v f="$org_file" '$1 == "file" && $3 == f {print $2}' .org-export-state) + if [ -f .org-export-state ]; then + recorded=$(state_lookup "$org_file") + fi if [ -f "$html_file" ] && [ -n "$recorded" ] && [ "$recorded" = "$fingerprint" ]; then return 2 # unchanged @@ -54,14 +92,7 @@ export_org_to_html() { return 1 fi - # record the successful export under the file lock the state rewrite takes - { - flock 9 - grep -v -F "$(printf 'file\t')" .org-export-state 2>/dev/null > .org-export-state.tmp - printf 'file\t%s\t%s\n' "$fingerprint" "$org_file" >> .org-export-state.tmp - sort -o .org-export-state.tmp .org-export-state.tmp - mv .org-export-state.tmp .org-export-state - } 9>>.org-export-state.lock + state_record "$fingerprint" "$org_file" echo "✓ Successfully exported $org_file" return 0