From d1631a046ee02bc54ed4d41869220879badef365 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Tue, 29 Jun 2021 08:28:23 +0900 Subject: [PATCH] include/queue: Prevent queue_put_unique() from adding duplicates There are several issues in _queue_contains(), causing the queue_put_unique() function to hang (waiting for input from stdin) or add duplicate items to the queue. This commit addresses these issues so that queue_put_unique() does not hang or add duplicate items. --- include/queue.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/queue.sh b/include/queue.sh index 0eceda2..4dee147 100644 --- a/include/queue.sh +++ b/include/queue.sh @@ -224,15 +224,19 @@ _queue_contains() { local item="$2" local data - local qdata + local qitem data=$(_queue_get_data "$queue") - while read -r qdata; do - if [[ "$qdata" == "$data" ]]; then + if ! [ -f "$data" ]; then + return 1 + fi + + while read -r qitem; do + if [[ "$qitem" == "$item" ]]; then return 0 fi - done + done < "$data" return 1 } -- 2.47.3