From 57fcdef4fe672da3529402bdaff0021549dff7b3 Mon Sep 17 00:00:00 2001 From: Urban Modig Date: Wed, 1 Oct 2025 11:55:01 +0200 Subject: [PATCH] fix set -e --- download.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/download.sh b/download.sh index 0494129..4e941a1 100755 --- a/download.sh +++ b/download.sh @@ -43,7 +43,14 @@ LOCK_HELD=0 lock() { log "Creating lock… ($LOCK_FILE)" - exec ${LOCK_FD}>"$LOCK_FILE" || die "Could not open lock file $LOCK_FILE" + # Use a literal FD number for portability: exec 200>"$LOCK_FILE" + exec 200>"$LOCK_FILE" || die "Could not open lock file $LOCK_FILE" + if flock -n 200; then + LOCK_HELD=1 + else + die "Lock failed — another process is running." + fi +}>"$LOCK_FILE" || die "Could not open lock file $LOCK_FILE" if flock -n ${LOCK_FD}; then LOCK_HELD=1 else @@ -54,7 +61,12 @@ lock() { unlock() { if (( LOCK_HELD )); then log "Releasing lock…" - flock -u ${LOCK_FD} || true + flock -u 200 || true + # Close the FD to avoid lingering descriptors + exec 200>&- || true + LOCK_HELD=0 + fi +} || true # Close the FD to avoid lingering descriptors exec ${LOCK_FD}>&- || true LOCK_HELD=0 @@ -351,4 +363,3 @@ fi # cleanup happens via trap exit 0 - \ No newline at end of file