From db20b099541964df23d8548f6a35447bc1e41065 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Mon, 29 Aug 2022 21:02:05 +1000 Subject: [PATCH] fix bug in bash v5 when allocating new ids --- t.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/t.sh b/t.sh index fc78a5c..035abec 100755 --- a/t.sh +++ b/t.sh @@ -143,10 +143,17 @@ function getuid() { function updatenextid() { local nextid2=1 + local db=0 nextid2=1 - while [[ " ${taskid[@]}" == *\ $nextid2* ]]; do - nextid2=$((nextid2 + 1)) - done + if [[ $b5 -eq 1 ]]; then + while [[ " ${i_idmap[@]}" == *\ $nextid2* ]]; do + nextid2=$((nextid2 + 1)) + done + else + while [[ " ${taskid[@]}" == *\ $nextid2* ]]; do + nextid2=$((nextid2 + 1)) + done + fi nextid=$nextid2 } @@ -175,6 +182,7 @@ function loadids() { id=${LINE#*:} #uid=$(echo "$LINE" | sed 's/:.*$//g') #id=$(echo "$LINE" | sed 's/^.*://g') + addidmap $id $uid if [[ -z $uid || -z $id ]]; then error "invalid idmapping line: '$LINE'" @@ -318,6 +326,7 @@ function confirm() { function loadtask() { local uid sum checked folded desc file id parent res i cats local blockreason + local didalloc=0 #local re #if iscached "$1"; then @@ -341,7 +350,7 @@ dblog "process token '${tok[$i]}'" if [[ -z $id ]]; then id=$nextid addidmap $nextid $uid - updatenextid + didalloc=1 needsave=1 fi elif [[ ${tok[$i]} == "sum" ]]; then @@ -388,6 +397,9 @@ dblog "process token '${tok[$i]}'" [[ $id -gt $maxid ]] && maxid=$id [[ ${#sum} -gt $taskwid ]] && taskwid=${#sum} [[ ${#desc} -gt $taskwid ]] && taskwid=${#desc} + + [[ $didalloc -eq 1 ]] && updatenextid + if [[ -z $uid ]]; then error "task has no uid:" echo "$res"