diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-28 09:19:33 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-28 09:19:33 +0300 |
| commit | 86c354932e698d52f23e65a1dafb1b7250f4c1b9 (patch) | |
| tree | 2b67fdfab41fab1036c55e91bd2ddf72c25829dd /bin | |
| parent | 94479238557adcab33a95fefbf752a3742b8a8ba (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 'bin')
| -rwxr-xr-x | bin/shuriken | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/bin/shuriken b/bin/shuriken index a85c44e..0a4450d 100755 --- a/bin/shuriken +++ b/bin/shuriken @@ -2047,6 +2047,22 @@ camera_label_from_make_model() { # dependency, it does not affect availability. Behaviour and signatures are # unchanged by the move. +# The volatile EXIF cache directory: ./cache/exif parallel to ./dist. Computed +# once here (task pr0) from working_dir() (the parent of DIST_DIR) so the path is +# defined in exactly ONE place. It was previously recomputed inline -- byte for +# byte identically -- in both cached_photo_identify_output (read/write) and +# clear_exif_cache (remove for --force/--clean); a single source for it keeps +# those two in lockstep so the reader and the cleaner can never drift apart and +# point at different directories. The path is deliberately a sibling of DIST_DIR +# (working_dir()/cache/exif): the staging dir is a sibling of the final dist, so +# this resolves to the working dir in both staging and direct contexts, lives +# outside dist (surviving a fresh/cleared dist and never deployed), and lets an +# unchanged photo skip the slow `identify -verbose` on every regenerate. +# printf (no echo) keeps it safe under `set -euo pipefail`. +exif_cache_dir() { + printf '%s\n' "$(working_dir)/cache/exif" +} + # Build the cache signature line ("<photo>:<size>:<mtime>") used to decide # whether a cache entry is still valid for the source file. Kept private to this # module alongside its only consumers, plus the stats test that pre-seeds caches. @@ -2086,12 +2102,11 @@ cached_photo_identify_output() { local current_signature local identify_status - # Persist the EXIF cache in a volatile ./cache directory parallel to ./dist - # (the staging dir is a sibling of the final dist, so dirname "$DIST_DIR" is - # the working dir in both staging and direct contexts). Keeping it outside - # dist means it survives a fresh/cleared dist and is never deployed, so an - # unchanged photo skips the slow `identify -verbose` on every regenerate. - cache_dir="$(dirname "$DIST_DIR")/cache/exif" + # Resolve the volatile EXIF cache dir via the shared exif_cache_dir() helper + # (see its definition above for why it sits parallel to ./dist and survives a + # cleared dist) so the reader/writer here and clear_exif_cache below always + # agree on the same directory. + cache_dir="$(exif_cache_dir)" cache_file="$cache_dir/$photo.txt" current_signature=$(photo_cache_signature "$photo" "$photo_path") @@ -2188,7 +2203,7 @@ photo_exif_values_to() { # lifecycle counterpart of cached_photo_identify_output above, so the cache's # creation and destruction now live in the same module. clear_exif_cache() { - local -r cache_dir="$(dirname "$DIST_DIR")/cache/exif" + local -r cache_dir="$(exif_cache_dir)" log_verbose "Force generation; clearing EXIF cache $cache_dir" rm -rf "$cache_dir" @@ -5517,6 +5532,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:-}" @@ -6662,14 +6691,15 @@ log_configured_action() { # Safety: callers MUST run validate_clean_dist_dir first so a dangerous DIST_DIR # aborts before any deletion. We only match shuriken's own, basename-specific # staging/backup prefixes (never a loose ".shuriken.*" or arbitrary dotfiles), -# derive the parent exactly as the staging code does (dirname "$DIST_DIR"), and -# use nullglob so a missing match never expands to a literal pattern to rm. +# derive the parent via working_dir() (the shared plain `dirname "$DIST_DIR"`, +# exactly the parent the staging code stages into), and use nullglob so a missing +# match never expands to a literal pattern to rm. clean_generation_staging_artifacts() { local final_base final_parent artifact local -a artifacts=() final_base=$(basename "$DIST_DIR") - final_parent=$(dirname "$DIST_DIR") + final_parent=$(working_dir) # nullglob: a non-matching glob expands to nothing rather than to the # literal pattern, so we never accidentally rm a path called "*". |
