summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavide Cavalca <dcavalca@fb.com>2021-12-06 12:03:57 -0800
committerGitHub <noreply@github.com>2021-12-06 12:03:57 -0800
commit4108a874dd150fe1ce6a4fe5782b1b32b390fcd7 (patch)
tree5b6bba50acdaca66d29cd7b6832e92950d7fe6e5 /lib
parent8f4752b48a666630a1287c5f904a90b60fbea016 (diff)
downloadohai-4108a874dd150fe1ce6a4fe5782b1b32b390fcd7.tar.gz
Fix parsing bug in the rpm plugin (#1719)
Signed-off-by: Davide Cavalca <dcavalca@fb.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ohai/plugins/rpm.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/ohai/plugins/rpm.rb b/lib/ohai/plugins/rpm.rb
index 7f4870b1..c131ad50 100644
--- a/lib/ohai/plugins/rpm.rb
+++ b/lib/ohai/plugins/rpm.rb
@@ -91,17 +91,27 @@ Ohai.plugin(:Rpm) do
value = ""
lines[macros_start_idx + 1..macros_end_idx - 1].each do |line|
if line.start_with?("-")
+ # new macros are always prefixed by a dash
if name
+ # if we had parsed a macro before, store it
rpm[:macros][name] = value
name = nil
value = ""
- else
- _prefix, name, value = line.split(" ", 3)
end
+
+ # parse the new macro definition
+ _prefix, name, value = line.split(" ", 3)
else
+ # continuations have no prefix and just append to the previous one
value += "\n#{line}"
end
end
+
+ # Once we're done parsing all lines, we might have a parsed definition
+ # we haven't stored - if so, store it.
+ if name
+ rpm[:macros][name] = value
+ end
else
logger.trace("Plugin RPM: Could not find rpm. Skipping plugin.")
end