From: Matthias Kruk Date: Mon, 28 Jun 2021 23:28:23 +0000 (+0900) Subject: include/queue: Prevent queue_put_unique() from adding duplicates X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=d1631a046ee02bc54ed4d41869220879badef365;p=toolbox 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. --- 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 }