Skip to content

package: pacman provider: Add purgeable feature #9287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/puppet/provider/package/pacman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def self.yaourt?
has_feature :uninstall_options
has_feature :upgradeable
has_feature :virtual_packages
has_feature :purgeable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't even required and somehow automatically enabled when a purge method exists? but some providers explicitly enable it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity, since the package type defines the purgeable feature as depending on the purge method

feature :purgeable, "The provider can purge packages. This generally means
that all traces of the package are removed, including
existing configuration files. This feature is thus destructive
and should be used with the utmost care.",
:methods => [:purge]

Then it is not strictly necessary to specify has_feature due to the available check in

(is_a?(Class) ? declared_feature?(name) : self.class.declared_feature?(name)) or feature.available?(self)

See related commits 5b2ffbc and 3d17685


# Checks if a given name is a group
def self.group?(name)
Expand Down Expand Up @@ -191,6 +192,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)
Expand All @@ -201,6 +212,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?
Expand All @@ -210,8 +222,6 @@ def uninstall
end
end

private

def install_options
join_options(@resource[:install_options])
end
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/provider/package/pacman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
Loading