]> git.corax.cc Git - toolbox/commitdiff
include/queue: Prevent queue_put_unique() from adding duplicates
authorMatthias Kruk <m@m10k.eu>
Mon, 28 Jun 2021 23:28:23 +0000 (08:28 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 28 Jun 2021 23:28:23 +0000 (08:28 +0900)
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

index 0eceda2699c21d0c0213c8c9b672f96f34e0026c..4dee147a30735ec7d059db94b162b56d9dcd2940 100644 (file)
@@ -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
 }