[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

View file

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