bneradt commented on code in PR #13237:
URL: https://github.com/apache/trafficserver/pull/13237#discussion_r3358755523


##########
tests/tools/condwait:
##########
@@ -55,24 +61,43 @@ if [[ "$X" = "$1" ]] ; then
 fi
 
 if [[ "$1" = "" ]] ; then
-    echo "usage: condwait [ MAX-WAIT [ POST-WAIT ] ] TEST-CONDTION" >&2
+    usage
     exit 1
 fi
 
-# Check if this is a simple file existence test (-f, -e, -d). If so, use ls -d
-# which handles glob patterns properly. Otherwise, use test for the condition.
+if [[ "$1" = "--contains" ]]; then
+    if [[ $# -ne 4 ]] || ! [[ "$4" =~ ^[0-9]+$ ]]; then
+        usage
+        exit 1
+    fi
+fi
+
+# Check simple file existence tests (-f, -e, -d) specially so literal paths 
with
+# whitespace work while glob patterns remain supported.
 check_condition() {
-    if [[ "$1" = "-f" || "$1" = "-e" || "$1" = "-d" ]] && [[ $# -eq 2 ]]; then
-        # Use ls -d for file existence tests to support glob patterns.
-        ls -d $2 >/dev/null 2>&1
+    if [[ "$1" = "--contains" ]]; then
+        [[ -f "$2" ]] || return 1
+        local matches
+        matches=$(awk -v pattern="$3" 'index($0, pattern) { count++ } END { 
print count + 0 }' "$2")
+        (( matches >= $4 ))

Review Comment:
   OK. Addressed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to