[type/__uci] Unquote UCI reported values

Without unquoting values printed in single quotes by UCI would always lead to
the state explorer reporting "different".
This commit is contained in:
Dennis Camera 2020-10-24 21:11:50 +02:00
parent b99ca3cbdf
commit 8728817af6
1 changed files with 15 additions and 2 deletions

View File

@ -51,21 +51,34 @@ fi
# strip off trailing newline
printf '%s' "${values_is}" \
| awk '
function unquote(s) {
# simplified dequoting of single quoted strings
if (s ~ /^'\''.*'\''$/) {
s = substr(s, 2, length(s) - 2)
sub(/'"'\\\\''"'/, "'\''", s)
}
return s
}
BEGIN {
state = "present" # assume all is fine
}
NR == FNR {
# memoize "should" state
should[FNR] = $0
should_count++
# go to next line (important!)
next
}
# compare "is" state
{ $0 = unquote($0) }
$0 == should[FNR] { next }
FNR > length(should) {
FNR > should_count {
# there are more "is" records than "should" -> definitely different
state = "different"
exit
@ -87,7 +100,7 @@ FNR > length(should) {
}
END {
if (FNR < length(should)) {
if (FNR < should_count) {
# "is" was shorter than "should" -> different
state = "different"
}