From 31c302f7f0979bbaad83b9e67f5985a3bff9f124 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 10 Mar 2024 15:32:07 +0100 Subject: [PATCH] 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] options: -b, --dbpath 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 08eaa3d23e8c5344791792b8beeff4f25c589b85) --- lib/puppet/provider/package/pacman.rb | 14 ++++++++++++-- spec/unit/provider/package/pacman_spec.rb | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/package/pacman.rb b/lib/puppet/provider/package/pacman.rb index 600721faaab..6a8833cdea5 100644 --- a/lib/puppet/provider/package/pacman.rb +++ b/lib/puppet/provider/package/pacman.rb @@ -23,6 +23,7 @@ def self.yaourt? has_feature :uninstall_options has_feature :upgradeable has_feature :virtual_packages + has_feature :purgeable # Checks if a given name is a group def self.group?(name) @@ -193,6 +194,16 @@ def self.to_resource_hash(name, version) # Removes a package from the system. def uninstall + remove_package(false) + end + + def purge + remove_package(true) + end + + private + + def remove_package(purge_configs = false) resource_name = @resource[:name] is_group = self.class.group?(resource_name) @@ -203,6 +214,7 @@ def uninstall cmd += uninstall_options if @resource[:uninstall_options] cmd << "-R" cmd << '-s' if is_group + cmd << '--nosave' if purge_configs cmd << resource_name if self.class.yaourt? @@ -212,8 +224,6 @@ def uninstall end end - private - def install_options join_options(@resource[:install_options]) end diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb index f1516ffc269..57784e53dd1 100644 --- a/spec/unit/provider/package/pacman_spec.rb +++ b/spec/unit/provider/package/pacman_spec.rb @@ -168,6 +168,14 @@ end end + describe "when purging" do + it "should call pacman to remove the right package and configs quietly" do + args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", "--nosave", resource[:name]] + expect(executor).to receive(:execute).with(args, no_extra_options).and_return("") + provider.purge + end + end + describe "when uninstalling" do it "should call pacman to remove the right package quietly" do args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", resource[:name]]