Skip to content

Commit 31c302f

Browse files
bastelfreakgithub-actions[bot]
authored andcommitted
package: pacman provider: Add purgeable feature
This small patch adds an option to the pacman provider to purge config files. From the manpage: ```console $ pacman -R -h | head -n6 usage: pacman {-R --remove} [options] <package(s)> options: -b, --dbpath <path> set an alternate database location -c, --cascade remove packages and all packages that depend on them -d, --nodeps skip dependency version checks (-dd to skip all checks) -n, --nosave remove configuration files ``` (cherry picked from commit 08eaa3d)
1 parent a1d2344 commit 31c302f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/puppet/provider/package/pacman.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def self.yaourt?
2323
has_feature :uninstall_options
2424
has_feature :upgradeable
2525
has_feature :virtual_packages
26+
has_feature :purgeable
2627

2728
# Checks if a given name is a group
2829
def self.group?(name)
@@ -193,6 +194,16 @@ def self.to_resource_hash(name, version)
193194

194195
# Removes a package from the system.
195196
def uninstall
197+
remove_package(false)
198+
end
199+
200+
def purge
201+
remove_package(true)
202+
end
203+
204+
private
205+
206+
def remove_package(purge_configs = false)
196207
resource_name = @resource[:name]
197208

198209
is_group = self.class.group?(resource_name)
@@ -203,6 +214,7 @@ def uninstall
203214
cmd += uninstall_options if @resource[:uninstall_options]
204215
cmd << "-R"
205216
cmd << '-s' if is_group
217+
cmd << '--nosave' if purge_configs
206218
cmd << resource_name
207219

208220
if self.class.yaourt?
@@ -212,8 +224,6 @@ def uninstall
212224
end
213225
end
214226

215-
private
216-
217227
def install_options
218228
join_options(@resource[:install_options])
219229
end

spec/unit/provider/package/pacman_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@
168168
end
169169
end
170170

171+
describe "when purging" do
172+
it "should call pacman to remove the right package and configs quietly" do
173+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", "--nosave", resource[:name]]
174+
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
175+
provider.purge
176+
end
177+
end
178+
171179
describe "when uninstalling" do
172180
it "should call pacman to remove the right package quietly" do
173181
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", resource[:name]]

0 commit comments

Comments
 (0)