Skip to contentSkip to conversation

runtime.bash: fix check for parameter files

PATCH In review Paolo Bonzini 3 participants 3 messages Sep 28, 2020 KVM

lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 runtime.bash: fix check for parameter files

We need to check if the file exists, not just if it is a non-empty string. While an empty $path would have the unfortunate effect that "cat" would read from stdin, that is not an issue as you can simply not do that.

---
 scripts/runtime.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/runtime.bash +1 -1
index 294e6b1..3121c1f 100644
@@ -118,7 +118,7 @@ function run()
     for check_param in "${check[@]}"; do
         path=${check_param%%=*}
         value=${check_param#*=}
-        if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
+        if [ -f "$path" ] && [ "$(cat $path)" != "$value" ]; then
             print_result "SKIP" $testname "" "$path not equal to $value"
             return 2
         fi
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Paolo Bonzini

We need to check if the file exists, not just if it is a non-empty string. While an empty $path would have the unfortunate effect that "cat" would read from stdin, that is not an issue as you can simply not do that.

---
 scripts/runtime.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/runtime.bash +0 -0
index 294e6b1..3121c1f 100644

scripts/runtime.bash function run() · line 124

Quoted 8 lines
scripts/runtime.bash +1 -1
@@ -118,7 +118,7 @@ function run()
     for check_param in "${check[@]}"; do
         path=${check_param%%=*}
         value=${check_param#*=}
-        if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
+        if [ -f "$path" ] && [ "$(cat $path)" != "$value" ]; then
             print_result "SKIP" $testname "" "$path not equal to $value"
             return 2
         fi
Reviewed-by on v1 1/1
#2 lore raw
In reply to Paolo Bonzini
Quoted 25 lines · Paolo Bonzini

We need to check if the file exists, not just if it is a non-empty string. While an empty $path would have the unfortunate effect that "cat" would read from stdin, that is not an issue as you can simply not do that.

---
 scripts/runtime.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/runtime.bash +1 -1
index 294e6b1..3121c1f 100644
@@ -118,7 +118,7 @@ function run()
     for check_param in "${check[@]}"; do
         path=${check_param%%=*}
         value=${check_param#*=}
-        if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
+        if [ -f "$path" ] && [ "$(cat $path)" != "$value" ]; then
             print_result "SKIP" $testname "" "$path not equal to $value"
             return 2
         fi
Signature · 1 line
2.26.2