Skip to content
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

package: pacman provider: Add purgeable feature #9287

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

bastelfreak
Copy link
Contributor

This small patch adds an option to the pacman provider to purge config files.

From the manpage:

$ 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

@bastelfreak bastelfreak requested a review from a team as a code owner March 10, 2024 14:34
@puppetlabs-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@bastelfreak
Copy link
Contributor Author

I did some local testing and this works as expected:

# puppet resource package htop ensure=purged --debug
Debug: Prefetching pacman resources for package
Debug: Executing '/usr/bin/pacman -Q'
Debug: Executing '/usr/bin/pacman -Sgg'
Debug: Executing: '/usr/bin/pacman -Sg htop'
Debug: Executing: '/usr/bin/pacman --noconfirm --noprogressbar -R --nosave htop'
Notice: /Package[htop]/ensure: purged
Debug: Finishing transaction 10180
Debug: Storing state
Debug: Pruned old state cache entries in 0.00 seconds
Debug: Stored state in 0.01 seconds
Debug: Executing '/usr/bin/pacman -Q'
Debug: Executing '/usr/bin/pacman -Sgg htop'

@@ -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

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
```
@bastelfreak
Copy link
Contributor Author

I added a test and they seem to pass? Let me know if this is what you had in mind.

@joshcooper joshcooper merged commit b3aacd2 into puppetlabs:main Mar 12, 2024
9 checks passed
@joshcooper
Copy link
Contributor

Thanks @bastelfreak !

@bastelfreak
Copy link
Contributor Author

Thanks! Any chance this can go into 7 as well? I can provide a new PR if you like.

@joshcooper joshcooper added the backport 7.x Generate a backport PR to 7.x label Mar 12, 2024
Copy link

Successfully created backport PR for 7.x:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 7.x Generate a backport PR to 7.x enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants