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

Clear pacman cache #70

Closed
Temet79 opened this issue Dec 3, 2023 · 4 comments · Fixed by #71
Closed

Clear pacman cache #70

Temet79 opened this issue Dec 3, 2023 · 4 comments · Fixed by #71
Assignees
Labels
feature/request New feature or request

Comments

@Temet79
Copy link
Contributor

Temet79 commented Dec 3, 2023

Hello Antiz,

I would add a pull request but I actually don't know how it works :(

I added this to the script on my own to clear the cache, I was doing manually after updates.
Feel free to add and improve you want.

# Definition of the clear_paccache function: Remove previous versions of packages from clear_paccache
clear_paccache() {
  cache_old=$(paccache -dk2 | sed -n 's/.*: \([0-9]*\) candidate.*/\1/p')
  [ -z "$cache_old" ] && cache_old=0
  cache_uninstalled=$(paccache -duk0 | sed -n 's/.*: \([0-9]*\) candidate.*/\1/p')
  [ -z "$cache_uninstalled" ] && cache_uninstalled=0
  cache_total=$(($cache_old+$cache_uninstalled))

  if [ $cache_total -gt 0 ]; then
    if [ $cache_total -eq 1 ]; then
      read -rp $'Would you like to remove the older package version stored in cache? [Y/n] ' answer
    elif [ $cache_total -gt 1 ]; then
      echo $cache_total older packages versions are stored in cache.
      read -rp $'Would you like to remove them? [Y/n] ' answer
    fi

    case "${answer}" in
      [Yy]|"")
        "${su_cmd}" paccache -rk2
        "${su_cmd}" paccache -ruk0
      ;;
    esac
  fi
}
@Antiz96
Copy link
Owner

Antiz96 commented Dec 3, 2023

Hello,

Thanks a lot for the great suggestion, and the example!
I'm currently working on implementing it, taking inspiration from your code ;)

@Antiz96 Antiz96 self-assigned this Dec 3, 2023
@Antiz96 Antiz96 added the feature/request New feature or request label Dec 3, 2023
Antiz96 added a commit that referenced this issue Dec 3, 2023
…he and offers to remove them if there are

As suggested in #70, this commit aims to add function to the script to check for old or uninstalled packages in pacman's cache and offers to remove them if there are.

The check and removal are based on paccache (from the [pacman-contrib package](https://archlinux.org/packages/extra/x86_64/pacman-contrib/)).
The default behavior is to keep the last 3 cached versions of installed packages and remove every cached versions of uninstalled packages.

Closes #70
Antiz96 added a commit that referenced this issue Dec 3, 2023
…he and offers to remove them if there are (#71)

* Check if there are old or uninstalled cached packages in pacman's cache and offers to remove them if there are
As suggested in #70, this commit aims to add function to the script to check for old or uninstalled packages in pacman's cache and offers to remove them if there are.

The check and removal are based on paccache (from the [pacman-contrib package](https://archlinux.org/packages/extra/x86_64/pacman-contrib/)).
The default behavior is to keep the last 3 cached versions of installed packages and remove every cached versions of uninstalled packages.

Closes #70

* Fix var names

* Syntax and style changes

* Syntax and style changes

* Syntax and style changes

* Add documentation for the new 'cache checking' function
@Antiz96
Copy link
Owner

Antiz96 commented Dec 3, 2023

Feature implemented in #71.
I set the number of kept cached versions to 3 instead of 2 though. It is the default value applied by paccache and feels like a sane/safe behavior.

I will release v1.9.0 in a moment, including this new feature.
Thanks once again for the suggestion and the implementation example 😄

@Antiz96
Copy link
Owner

Antiz96 commented Dec 3, 2023

@Antiz96
Copy link
Owner

Antiz96 commented Jan 7, 2024

Hi,

Just in case, the latest v1.10.0 release now includes an optional arch-update.conf configuration file that allows you to enable/disable or modify certain options within the script, including the number of old and uninstalled packages to keep in pacman's cache.
So if you wanna get back to keeping only 2 old packages' version in pacman's cache, you can now specify it in your arch-update.conf 😉

The documentation for the new arch-update.conf is available in the README or in the arch-update.conf(5) man page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/request New feature or request
Projects
None yet
2 participants