summaryrefslogtreecommitdiff
path: root/src/lib/config.sync.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-27 11:05:50 +0300
committerPaul Buetow <paul@buetow.org>2026-06-27 11:05:50 +0300
commit9b16b1bc54213c7349ec9a44ba258466718c0f48 (patch)
treecba419df08735b3e157d325b5e8dd5a0a780dbec /src/lib/config.sync.source.sh
parent1d6a00fd71cb8ea093da2f217f1724f4d5df1c85 (diff)
qr0: timeout + per-destination isolation for rsync sync_dist
Wrap each rsync in sync_dist in run_with_timeout (new SYNC_TIMEOUT config, default 300s) so a hung or unreachable mirror cannot block the whole sync, matching every other external call. Make destinations isolated: under set -euo pipefail a single failing destination used to abort the loop and silently skip the rest. Now each destination runs under a localized set +e (the project's refresh_splash idiom), results are collected per destination, a clear pass/fail summary is logged, and sync returns non-zero if any destination failed while still attempting all of them. SYNC_TIMEOUT is plumbed like TAR_TIMEOUT: shuriken.default.conf, apply_config_defaults, print_config, verbose config log, and positive-integer validation in both validate_config (generate path) and validate_sync_config (sync path). No CLI flag, matching TAR_TIMEOUT. Tests: a sync where one destination fails still attempts the others and exits non-zero with the summary; SYNC_TIMEOUT=0 is rejected as a positive integer. Adds install_rsync_spy_failing_one helper and updates the print_config expected blocks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'src/lib/config.sync.source.sh')
-rw-r--r--src/lib/config.sync.source.sh38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/lib/config.sync.source.sh b/src/lib/config.sync.source.sh
index f4df169..35a7185 100644
--- a/src/lib/config.sync.source.sh
+++ b/src/lib/config.sync.source.sh
@@ -40,6 +40,9 @@ sync_dist() {
local destination
local -a rsync_args=(-av)
local -a sync_destinations=()
+ local -a succeeded=()
+ local -a failed=()
+ local -i status=0
resolve_sync_destinations sync_destinations
@@ -47,8 +50,41 @@ sync_dist() {
rsync_args+=(--delete)
fi
+ # Mirror to every destination with per-destination isolation: a timeout or
+ # rsync error on one mirror must NOT abort the others (under the top-level
+ # "set -euo pipefail" a bare failing rsync would otherwise kill the loop and
+ # silently skip the remaining destinations). We wrap each rsync in
+ # run_with_timeout (SYNC_TIMEOUT) like every other external call, and use the
+ # project's localized "set +e" idiom (see refresh_splash / bash-best-
+ # practices) to capture each destination's status instead of aborting. The
+ # "if ! run_with_timeout ...; then" form is avoided here because its non-zero
+ # branch would still leave $? ambiguous for the summary; the explicit status
+ # capture keeps the per-destination result unambiguous.
for destination in "${sync_destinations[@]}"; do
log_info "Syncing $DIST_DIR/ to $destination"
- rsync "${rsync_args[@]}" "$DIST_DIR/" "$destination"
+ set +e
+ run_with_timeout "rsync to $destination" "$SYNC_TIMEOUT" \
+ rsync "${rsync_args[@]}" "$DIST_DIR/" "$destination"
+ status=$?
+ set -e
+ if (( status == 0 )); then
+ succeeded+=("$destination")
+ else
+ # run_with_timeout already prints a timeout/error line; add a
+ # per-destination notice so the operator sees which mirror failed.
+ failed+=("$destination")
+ log_warning "Sync to $destination failed (status $status)"
+ fi
done
+
+ # Log a clear pass/fail summary and return non-zero if ANY destination
+ # failed, while having ATTEMPTED all of them.
+ if (( ${#succeeded[@]} > 0 )); then
+ log_info "Sync succeeded for: ${succeeded[*]}"
+ fi
+ if (( ${#failed[@]} > 0 )); then
+ log_warning "Sync failed for: ${failed[*]}"
+ return 1
+ fi
+ return 0
}