Skip to content

Commit 50a18b6

Browse files
committed
(PUP-3631) Allow nim to install RPM packages with letters in version
This commit adapts the regular expression from the `nim` package provider used for parsing RPM package versions to allow installation of RPM packages that have letters in their version instead of throwing error.
1 parent 18e1fde commit 50a18b6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/puppet/provider/package/nim.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def install(useversion = true)
156156
# do so.
157157
self::HEADER_LINE_REGEX = /^([^\s]+)\s+[^@]+@@(I|R|S):(\1)\s+[^\s]+$/
158158
self::PACKAGE_LINE_REGEX = /^.*@@(I|R|S):(.*)$/
159-
self::RPM_PACKAGE_REGEX = /^(.*)-(.*-\d+) \2$/
159+
self::RPM_PACKAGE_REGEX = /^(.*)-(.*-\d+\w*) \2$/
160160
self::INSTALLP_PACKAGE_REGEX = /^(.*) (.*)$/
161161

162162
# Here is some sample output that shows what the above regexes will be up

spec/unit/provider/package/nim_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,27 @@
191191
expect(versions[version]).to eq(:rpm)
192192
end
193193
end
194+
195+
it "should be able to parse RPM package listings with letters in version" do
196+
showres_output = <<END
197+
cairo ALL @@R:cairo _all_filesets
198+
@@R:cairo-1.14.6-2waixX11 1.14.6-2waixX11
199+
END
200+
packages = subject.send(:parse_showres_output, showres_output)
201+
expect(Set.new(packages.keys)).to eq(Set.new(['cairo']))
202+
versions = packages['cairo']
203+
expect(versions.has_key?('1.14.6-2waixX11')).to eq(true)
204+
expect(versions['1.14.6-2waixX11']).to eq(:rpm)
205+
end
206+
207+
it "should raise error when parsing invalid RPM package listings" do
208+
showres_output = <<END
209+
cairo ALL @@R:cairo _all_filesets
210+
@@R:cairo-invalid_version invalid_version
211+
END
212+
expect{ subject.send(:parse_showres_output, showres_output) }.to raise_error(Puppet::Error,
213+
/Unable to parse output from nimclient showres: package string does not match expected rpm package string format/)
214+
end
194215
end
195216

196217
context "#determine_latest_version" do

0 commit comments

Comments
 (0)