summaryrefslogtreecommitdiff
path: root/src/lib/config.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-28 09:19:33 +0300
committerPaul Buetow <paul@buetow.org>2026-06-28 09:19:33 +0300
commit86c354932e698d52f23e65a1dafb1b7250f4c1b9 (patch)
tree2b67fdfab41fab1036c55e91bd2ddf72c25829dd /src/lib/config.source.sh
parent94479238557adcab33a95fefbf752a3742b8a8ba (diff)
Centralize DIST_DIR-derived paths via working_dir/exif_cache_dir helpers
The EXIF cache dir ($(dirname "$DIST_DIR")/cache/exif) was recomputed inline, byte for byte, in both cached_photo_identify_output (read/write) and clear_exif_cache (--force/--clean removal). The plain parent of DIST_DIR (dirname "$DIST_DIR") was likewise recomputed in metadata-cache and in action.source.sh's staging-artifact cleanup. Extract two helpers computed once from DIST_DIR: - working_dir() in config.source.sh (next to existing_parent_dir, the other DIST_DIR-parent resolver): plain `dirname "$DIST_DIR"`. - exif_cache_dir() in metadata-cache.source.sh (owns the EXIF cache): `working_dir()/cache/exif`. Route cached_photo_identify_output, clear_exif_cache, and clean_generation_staging_artifacts through them so the cache reader and the cleaner can never drift to different directories. Paths are byte-identical to the prior inline code (dirname semantics, cache/exif suffix, trailing-slash and relative/absolute handling all preserved). Stale "recompute the cache dir" comments removed; helpers document the path once. Add a unit test asserting the helpers agree and resolve beside dist for several DIST_DIR shapes. Broader DIST_DIR parameterization of leaf pipeline helpers was intentionally left out of scope (only the duplicated path computation is centralized here). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'src/lib/config.source.sh')
-rw-r--r--src/lib/config.source.sh14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/config.source.sh b/src/lib/config.source.sh
index caa2fe3..c676899 100644
--- a/src/lib/config.source.sh
+++ b/src/lib/config.source.sh
@@ -11,6 +11,20 @@ existing_parent_dir() {
printf '%s\n' "$existing_parent"
}
+# The generation "working" directory: the parent of DIST_DIR. Several DIST_DIR
+# derived paths hang off this single parent -- the staging/backup sibling dirs
+# (config.staging, action) and the volatile EXIF cache (metadata-cache) all live
+# beside the final dist. Centralised here (task pr0), next to existing_parent_dir
+# (the other DIST_DIR-parent resolver), so the plain `dirname "$DIST_DIR"` is
+# computed in exactly one place instead of being recomputed at each call site.
+# Plain dirname (NOT existing_parent_dir): callers that previously inlined
+# `dirname "$DIST_DIR"` get a byte-identical result, including any trailing-slash
+# or relative-vs-absolute behaviour dirname already produced. printf (no echo) so
+# it stays safe under `set -euo pipefail`.
+working_dir() {
+ printf '%s\n' "$(dirname "$DIST_DIR")"
+}
+
resolve_config_file() {
local -r config_file="${1:-}"