From 9069bf91b58280cd67634e4c3f0af0b5e435a8d8 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Wed, 26 May 2021 13:31:15 +0900 Subject: [PATCH] include/queue: queue_foreach: Return failure if callback fails The queue_foreach() function always returns success, even if one of the callbacks failed. This makes it hard to handle errors that occur inside the callbacks. This commit changes the function to return failure if a callback has failed. --- include/queue.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/queue.sh b/include/queue.sh index b5bc03e..868d61b 100644 --- a/include/queue.sh +++ b/include/queue.sh @@ -500,9 +500,11 @@ queue_foreach() { local data local mutex local item + local err data=$(_queue_get_data "$name") mutex=$(_queue_get_mutex "$name") + err=0 if ! mutex_lock "$mutex"; then return 1 @@ -511,6 +513,7 @@ queue_foreach() { if [ -f "$data" ]; then while read -r item; do if ! "$func" "$item" "${args[@]}"; then + err=1 break fi done < "$data" @@ -518,5 +521,5 @@ queue_foreach() { mutex_unlock "$mutex" - return 0 + return "$err" } -- 2.47.3