Skip to content

Commit fc698a2

Browse files
authored
Merge pull request #9442 from bastelfreak/pacman2
Remove broken pacman command for installing packages
2 parents 5c078c8 + cf789b7 commit fc698a2

File tree

2 files changed

+44
-56
lines changed

2 files changed

+44
-56
lines changed

lib/puppet/provider/package/pacman.rb

+9-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.yaourt?
2929

3030
# Checks if a given name is a group
3131
def self.group?(name)
32-
!pacman("-Sg", name).empty?
32+
!pacman('--sync', '--groups', name).empty?
3333
rescue Puppet::ExecutionFailure
3434
# pacman returns an expected non-zero exit code when the name is not a group
3535
false
@@ -74,7 +74,7 @@ def self.instances
7474
# returns a hash package => version of installed packages
7575
def self.get_installed_packages
7676
packages = {}
77-
execpipe([command(:pacman), "-Q"]) do |pipe|
77+
execpipe([command(:pacman), "--query"]) do |pipe|
7878
# pacman -Q output is 'packagename version-rel'
7979
regex = /^(\S+)\s(\S+)/
8080
pipe.each_line do |line|
@@ -96,7 +96,7 @@ def self.get_installed_groups(installed_packages, filter = nil)
9696
groups = {}
9797
begin
9898
# Build a hash of group name => list of packages
99-
command = [command(:pacman), "-Sgg"]
99+
command = [command(:pacman), '--sync', '-gg']
100100
command << filter if filter
101101
execpipe(command) do |pipe|
102102
pipe.each_line do |line|
@@ -134,14 +134,14 @@ def latest
134134
resource_name = @resource[:name]
135135

136136
# If target is a group, construct the group version
137-
return pacman("-Sp", "--print-format", "%n %v", resource_name).lines.map(&:chomp).sort.join(', ') if self.class.group?(resource_name)
137+
return pacman("--sync", "--print", "--print-format", "%n %v", resource_name).lines.map(&:chomp).sort.join(', ') if self.class.group?(resource_name)
138138

139139
# Start by querying with pacman first
140140
# If that fails, retry using yaourt against the AUR
141141
pacman_check = true
142142
begin
143143
if pacman_check
144-
output = pacman "-Sp", "--print-format", "%v", resource_name
144+
output = pacman "--sync", "--print", "--print-format", "%v", resource_name
145145
output.chomp
146146
else
147147
output = yaourt "-Qma", resource_name
@@ -210,8 +210,8 @@ def remove_package(purge_configs = false)
210210

211211
cmd = %w[--noconfirm --noprogressbar]
212212
cmd += uninstall_options if @resource[:uninstall_options]
213-
cmd << "-R"
214-
cmd << '-s' if is_group
213+
cmd << "--remove"
214+
cmd << '--recursive' if is_group
215215
cmd << '--nosave' if purge_configs
216216
cmd << resource_name
217217

@@ -248,8 +248,7 @@ def install_from_file
248248
else
249249
fail _("Source %{source} is not supported by pacman") % { source: source }
250250
end
251-
pacman "--noconfirm", "--noprogressbar", "-S"
252-
pacman "--noconfirm", "--noprogressbar", "-U", source
251+
pacman "--noconfirm", "--noprogressbar", "--update", source
253252
end
254253

255254
def install_from_repo
@@ -260,7 +259,7 @@ def install_from_repo
260259

261260
cmd = %w[--noconfirm --needed --noprogressbar]
262261
cmd += install_options if @resource[:install_options]
263-
cmd << "-S" << resource_name
262+
cmd << "--sync" << resource_name
264263

265264
if self.class.yaourt?
266265
yaourt(*cmd)

spec/unit/provider/package/pacman_spec.rb

+35-46
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
end
2727

2828
it "should call pacman to install the right package quietly when yaourt is not installed" do
29-
args = ['--noconfirm', '--needed', '--noprogressbar', '-S', resource[:name]]
29+
args = ['--noconfirm', '--needed', '--noprogressbar', '--sync', resource[:name]]
3030
expect(provider).to receive(:pacman).at_least(:once).with(*args).and_return('')
3131
provider.install
3232
end
3333

3434
it "should call yaourt to install the right package quietly when yaourt is installed" do
3535
without_partial_double_verification do
3636
allow(described_class).to receive(:yaourt?).and_return(true)
37-
args = ['--noconfirm', '--needed', '--noprogressbar', '-S', resource[:name]]
37+
args = ['--noconfirm', '--needed', '--noprogressbar', '--sync', resource[:name]]
3838
expect(provider).to receive(:yaourt).at_least(:once).with(*args).and_return('')
3939
provider.install
4040
end
@@ -70,15 +70,15 @@
7070
end
7171

7272
it "should call pacman to install the right package quietly when yaourt is not installed" do
73-
args = ['--noconfirm', '--needed', '--noprogressbar', '-x', '--arg=value', '-S', resource[:name]]
73+
args = ['--noconfirm', '--needed', '--noprogressbar', '-x', '--arg=value', '--sync', resource[:name]]
7474
expect(provider).to receive(:pacman).at_least(:once).with(*args).and_return('')
7575
provider.install
7676
end
7777

7878
it "should call yaourt to install the right package quietly when yaourt is installed" do
7979
without_partial_double_verification do
8080
expect(described_class).to receive(:yaourt?).and_return(true)
81-
args = ['--noconfirm', '--needed', '--noprogressbar', '-x', '--arg=value', '-S', resource[:name]]
81+
args = ['--noconfirm', '--needed', '--noprogressbar', '-x', '--arg=value', '--sync', resource[:name]]
8282
expect(provider).to receive(:yaourt).at_least(:once).with(*args).and_return('')
8383
provider.install
8484
end
@@ -98,12 +98,7 @@
9898
resource[:source] = source
9999

100100
expect(executor).to receive(:execute).
101-
with(include("-S") & include("--noprogressbar"), no_extra_options).
102-
ordered.
103-
and_return("")
104-
105-
expect(executor).to receive(:execute).
106-
with(include("-U") & include(source), no_extra_options).
101+
with(include("--update") & include(source), no_extra_options).
107102
ordered.
108103
and_return("")
109104

@@ -121,13 +116,7 @@
121116

122117
it "should install from the path segment of the URL" do
123118
expect(executor).to receive(:execute).
124-
with(include("-S") & include("--noprogressbar") & include("--noconfirm"),
125-
no_extra_options).
126-
ordered.
127-
and_return("")
128-
129-
expect(executor).to receive(:execute).
130-
with(include("-U") & include(actual_file_path), no_extra_options).
119+
with(include("--update") & include(actual_file_path), no_extra_options).
131120
ordered.
132121
and_return("")
133122

@@ -170,58 +159,58 @@
170159

171160
describe "when purging" do
172161
it "should call pacman to remove the right package and configs quietly" do
173-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", "--nosave", resource[:name]]
162+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "--remove", "--nosave", resource[:name]]
174163
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
175164
provider.purge
176165
end
177166
end
178167

179168
describe "when uninstalling" do
180169
it "should call pacman to remove the right package quietly" do
181-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", resource[:name]]
170+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "--remove", resource[:name]]
182171
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
183172
provider.uninstall
184173
end
185174

186175
it "should call yaourt to remove the right package quietly" do
187176
without_partial_double_verification do
188177
allow(described_class).to receive(:yaourt?).and_return(true)
189-
args = ["--noconfirm", "--noprogressbar", "-R", resource[:name]]
178+
args = ["--noconfirm", "--noprogressbar", "--remove", resource[:name]]
190179
expect(provider).to receive(:yaourt).with(*args)
191180
provider.uninstall
192181
end
193182
end
194183

195184
it "adds any uninstall_options" do
196185
resource[:uninstall_options] = ['-x', {'--arg' => 'value'}]
197-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-x", "--arg=value", "-R", resource[:name]]
186+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-x", "--arg=value", "--remove", resource[:name]]
198187
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
199188
provider.uninstall
200189
end
201190

202191
it "should recursively remove packages when given a package group" do
203192
allow(described_class).to receive(:group?).and_return(true)
204-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", "-s", resource[:name]]
193+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "--remove", "--recursive", resource[:name]]
205194
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
206195
provider.uninstall
207196
end
208197
end
209198

210199
describe "when querying" do
211200
it "should query pacman" do
212-
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '-Q'])
213-
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg', 'package'])
201+
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '--query'])
202+
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg', 'package'])
214203
provider.query
215204
end
216205

217206
it "should return the version" do
218207
expect(executor).to receive(:execpipe).
219-
with(["/usr/bin/pacman", "-Q"]).and_yield(<<EOF)
208+
with(["/usr/bin/pacman", "--query"]).and_yield(<<EOF)
220209
otherpackage 1.2.3.4
221210
package 1.01.3-2
222211
yetanotherpackage 1.2.3.4
223212
EOF
224-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'package']).and_yield('')
213+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'package']).and_yield('')
225214

226215
expect(provider.query).to eq({ :name => 'package', :ensure => '1.01.3-2', :provider => :pacman, })
227216
end
@@ -239,8 +228,8 @@
239228

240229
describe 'when querying a group' do
241230
before :each do
242-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Q']).and_yield('foo 1.2.3')
243-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'package']).and_yield('package foo')
231+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--query']).and_yield('foo 1.2.3')
232+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'package']).and_yield('package foo')
244233
end
245234

246235
it 'should warn when allow_virtual is false' do
@@ -259,14 +248,14 @@
259248

260249
describe "when determining instances" do
261250
it "should retrieve installed packages and groups" do
262-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q'])
263-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg'])
251+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query'])
252+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg'])
264253
described_class.instances
265254
end
266255

267256
it "should return installed packages" do
268-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q']).and_yield(StringIO.new("package1 1.23-4\npackage2 2.00\n"))
269-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg']).and_yield("")
257+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query']).and_yield(StringIO.new("package1 1.23-4\npackage2 2.00\n"))
258+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg']).and_yield("")
270259
instances = described_class.instances
271260

272261
expect(instances.length).to eq(2)
@@ -285,11 +274,11 @@
285274
end
286275

287276
it "should return completely installed groups with a virtual version together with packages" do
288-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q']).and_yield(<<EOF)
277+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query']).and_yield(<<EOF)
289278
package1 1.00
290279
package2 1.00
291280
EOF
292-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg']).and_yield(<<EOF)
281+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg']).and_yield(<<EOF)
293282
group1 package1
294283
group1 package2
295284
EOF
@@ -315,10 +304,10 @@
315304
end
316305

317306
it "should not return partially installed packages" do
318-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q']).and_yield(<<EOF)
307+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query']).and_yield(<<EOF)
319308
package1 1.00
320309
EOF
321-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg']).and_yield(<<EOF)
310+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg']).and_yield(<<EOF)
322311
group1 package1
323312
group1 package2
324313
EOF
@@ -334,7 +323,7 @@
334323
end
335324

336325
it 'should sort package names for installed groups' do
337-
expect(described_class).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'group1']).and_yield(<<EOF)
326+
expect(described_class).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'group1']).and_yield(<<EOF)
338327
group1 aa
339328
group1 b
340329
group1 a
@@ -365,7 +354,7 @@
365354
it "should get query pacman for the latest version" do
366355
expect(executor).to receive(:execute).
367356
ordered.
368-
with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', resource[:name]], no_extra_options).
357+
with(['/usr/bin/pacman', '--sync', '--print', '--print-format', '%v', resource[:name]], no_extra_options).
369358
and_return("")
370359

371360
provider.latest
@@ -379,7 +368,7 @@
379368

380369
it "should return a virtual group version when resource is a package group" do
381370
allow(described_class).to receive(:group?).and_return(true)
382-
expect(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sp', '--print-format', '%n %v', resource[:name]], no_extra_options).ordered.
371+
expect(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--print', '--print-format', '%n %v', resource[:name]], no_extra_options).ordered.
383372
and_return(<<EOF)
384373
package2 1.0.1
385374
package1 1.0.0
@@ -394,17 +383,17 @@
394383
end
395384

396385
it 'should return false on non-zero pacman exit' do
397-
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sg', 'git'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_raise(Puppet::ExecutionFailure, 'error')
386+
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--groups', 'git'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_raise(Puppet::ExecutionFailure, 'error')
398387
expect(described_class.group?('git')).to eq(false)
399388
end
400389

401390
it 'should return false on empty pacman output' do
402-
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sg', 'git'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('')
391+
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--groups', 'git'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('')
403392
expect(described_class.group?('git')).to eq(false)
404393
end
405394

406395
it 'should return true on non-empty pacman output' do
407-
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sg', 'vim-plugins'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('vim-plugins vim-a')
396+
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--groups', 'vim-plugins'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('vim-plugins vim-a')
408397
expect(described_class.group?('vim-plugins')).to eq(true)
409398
end
410399
end
@@ -414,21 +403,21 @@
414403
let(:groups) { [['foo package1'], ['foo package2'], ['bar package3'], ['bar package4'], ['baz package5']] }
415404

416405
it 'should raise an error on non-zero pacman exit without a filter' do
417-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg 2>&1').and_return('error!')
406+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg 2>&1').and_return('error!')
418407
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(1)
419408
expect { described_class.get_installed_groups(installed_packages) }.to raise_error(Puppet::ExecutionFailure, 'error!')
420409
end
421410

422411
it 'should return empty groups on non-zero pacman exit with a filter' do
423-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg git 2>&1').and_return('')
412+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg git 2>&1').and_return('')
424413
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(1)
425414
expect(described_class.get_installed_groups(installed_packages, 'git')).to eq({})
426415
end
427416

428417
it 'should return empty groups on empty pacman output' do
429418
pipe = double()
430419
expect(pipe).to receive(:each_line)
431-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg 2>&1').and_yield(pipe).and_return('')
420+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg 2>&1').and_yield(pipe).and_return('')
432421
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(0)
433422
expect(described_class.get_installed_groups(installed_packages)).to eq({})
434423
end
@@ -438,7 +427,7 @@
438427
pipe_expectation = receive(:each_line)
439428
groups.each { |group| pipe_expectation = pipe_expectation.and_yield(*group) }
440429
expect(pipe).to pipe_expectation
441-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg 2>&1').and_yield(pipe).and_return('')
430+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg 2>&1').and_yield(pipe).and_return('')
442431
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(0)
443432
expect(described_class.get_installed_groups(installed_packages)).to eq({'foo' => 'package1 1.0, package2 2.0'})
444433
end

0 commit comments

Comments
 (0)