diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-14 15:26:24 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-14 15:26:24 +0300 |
| commit | 3eeef1e0f68d750e7817748180a2007095e99ef3 (patch) | |
| tree | 09962cd2a9e2cbb3fc7a662504a16d560ae9b614 /src | |
| parent | 67231312ba2d80592e305b08bbf03f7aece2e4a3 (diff) | |
lm0 harden resolve_config_array callers against set -e
The shared resolve_config_array helper returns non-zero when the source
config var was never declared. Both callers (resolve_tar_opts,
resolve_sync_destinations) invoked it unconditionally and ignored the
return value, so under set -euo pipefail a genuinely-unset TAR_OPTS or
SYNC_DESTINATIONS would abort the function before the empty-array
fallback could run. Currently masked because apply_config_defaults
always declares both vars, but the contract was unsafe to rely on.
Guard both call sites with `|| true` and document why: the empty array
the helper leaves behind is exactly what each caller's fallback expects.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/archive.source.sh | 5 | ||||
| -rw-r--r-- | src/lib/config.sync.source.sh | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/archive.source.sh b/src/lib/archive.source.sh index 3b173b7..b53a782 100644 --- a/src/lib/archive.source.sh +++ b/src/lib/archive.source.sh @@ -30,7 +30,10 @@ resolve_tar_opts() { # Parse TAR_OPTS (array or scalar) via the shared config-array helper, # then fall back to a plain "-c" whenever no options were configured, # whether TAR_OPTS was unset or set to an empty value. - resolve_config_array TAR_OPTS options_ref + # The helper returns non-zero when TAR_OPTS was never declared; we ignore + # that here (|| true) because the empty-array fallback below covers the + # unset case, and the bare non-zero return would otherwise trip set -e. + resolve_config_array TAR_OPTS options_ref || true if (( ${#options_ref[@]} == 0 )); then # shellcheck disable=SC2034 diff --git a/src/lib/config.sync.source.sh b/src/lib/config.sync.source.sh index 1707fe6..3d516dc 100644 --- a/src/lib/config.sync.source.sh +++ b/src/lib/config.sync.source.sh @@ -6,7 +6,10 @@ resolve_sync_destinations() { # Parse SYNC_DESTINATIONS (array or scalar) via the shared config-array # helper. Unlike TAR_OPTS there is no default: an unset or empty value # simply yields an empty destinations array for callers to validate. - resolve_config_array SYNC_DESTINATIONS destinations_ref + # The helper returns non-zero when SYNC_DESTINATIONS was never declared; + # we ignore that (|| true) since the already-empty array is exactly the + # desired result, and the bare non-zero return would otherwise trip set -e. + resolve_config_array SYNC_DESTINATIONS destinations_ref || true } sync_dist() { |
