yay icon indicating copy to clipboard operation
yay copied to clipboard

Command to remove old compiled packages

Open Emojigit opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

Yay's cache grows just like Pacman's. paccache from pacman-contrib can deal with Pacman's growing cache by conditional deleting old files, however, it does not work well on Yay.

Describe the solution you'd like

I want to see a Yay subcommand dedicated to (conditionally) cleaning Yay's cache (keeping the latest two compiled versions, removing caches for packages available in repositories, etc.).

Describe alternatives you've considered

I have tried using paccache. However, it is not designed to deal with the hierarchy of AUR, thus failing to clean up all files. Even worse, when coupled with a cleanup hook similar to pacman-cleanup-hook, it removes not-yet-installed packages, failing the installation process.

Emojigit avatar Jan 28 '24 14:01 Emojigit

You could point paccache to your yay cache (best as an alias): paccache='paccache --cachedir /<your yay cache> --cachedir /var/cache/pacman/pkg/'

I didn't like having different cache locations for packages though. Not a perfect solution and the makepkg wrapper sometimes needs work if the arguments change, but i've solved that by copying the packages over to the pacman cache and removing the packages from the yay cache (keeping the git stuff and thus having working diffs). I think i got the idea from some issue here, but i can't recall who to credit for that :hankey: For that, i have two wrappers for makepkg and pacman. Technically, it would be possible to only use the pacman wrapper, but that could leave packages in the yay cache if the installation is interrupted.

makepkg-wrapper:

#!/usr/bin/bash

# Setup this wrapper with
# > yay --makepkg ~/path/yay-makepkg --save

#echo "WRAPPER DEBUG OPTS: $@" >&2

makepkg "$@"
rc=$?

if [[ "$@" =~ '-f --noconfirm' ]];then
#    echo "Makepkg wrapper: trying to copy pkg to the main pacman cache with SUDO..." >&2
    echo "Makepkg wrapper: trying to copy pkg to the pacman/pkg/yay/ cache" >&2
    cp -vu --no-preserve=ownership,mode  ./*.pkg.tar.* /var/cache/pacman/pkg/yay/
fi
exit $rc 

pacman-wrapper:

#!/usr/bin/bash

# Setup this wrapper with
# > yay --pacman ~/path/yay-pacman --save

# echo "WRAPPER DEBUG OPTS: $@" >&2
arguments=("$@")  # Store the arguments in an array

pacman "$@"
rc=$?
 
if [[ "$rc" =~ '0' ]];then
    for argument in "${arguments[@]}"; do
        if [[ $argument == *".pkg.tar"* ]]; then
            echo "Deleting: $argument"
            rm $argument
        fi
    done
fi

exit $rc 

Termuellinator avatar Apr 13 '24 10:04 Termuellinator