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