From 8728817af6ae1fa801a39456df3f84d420f87744 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sat, 24 Oct 2020 21:11:50 +0200 Subject: [PATCH] [type/__uci] Unquote UCI reported values Without unquoting values printed in single quotes by UCI would always lead to the state explorer reporting "different". --- cdist/conf/type/__uci/explorer/state | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__uci/explorer/state b/cdist/conf/type/__uci/explorer/state index 6fb4b173..d7363dbf 100644 --- a/cdist/conf/type/__uci/explorer/state +++ b/cdist/conf/type/__uci/explorer/state @@ -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" }