On Thu, Oct 09, 2014 at 04:25:42PM +0200, Maxim Andersson wrote: > This option removes every uninstalled package in the cache.
Sorry for not replying to this sooner. > Signed-off-by: Maxim Andersson <[email protected]> > --- > contrib/paccache.sh.in | 62 > +++++++++++++++++++++++++++++++------------------- > 1 file changed, 39 insertions(+), 23 deletions(-) > > diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in > index 71aee23..02ccc22 100644 > --- a/contrib/paccache.sh.in > +++ b/contrib/paccache.sh.in > @@ -23,7 +23,7 @@ shopt -s extglob > declare -r myname='paccache' > declare -r myver='@PACKAGE_VERSION@' > > -declare -a cachedirs=() candidates=() cmdopts=() whitelist=() blacklist=() > +declare -a cachedirs=() candidates=() cmdopts=() whitelist=() blacklist=() > installedpkgs=() > declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 > verbose=0 > declare delim=$'\n' keep=3 movedir= scanarch= > > @@ -94,11 +94,18 @@ pkgfilter() { > > # create blacklist > blen = ARGV[i]; delete ARGV[i] > - while (i++ < ARGC) { > + while (i++ < 2 + wlen + blen) { > blacklist[ARGV[i]] = 1 > delete ARGV[i] > } > > + # create installedpkgs > + ilen = ARGV[i]; delete ARGV[i] > + while (i++ < ARGC) { > + installedpkgs[ARGV[i]] = 1 > + delete ARGV[i] > + } > + This seems an awful lot like you're special casing and duplicating the blacklist logic. How is calling: paccache --removceuninstall ... any different from: pacman -Qq | paccache -i- ... > # read package filenames > while (getline < "/dev/stdin") { > parse_filename($0) > @@ -108,9 +115,14 @@ pkgfilter() { > # idx[1,2] = idx[pkgname,arch] > split(pkglist, idx, SUBSEP) > > + count = split(packages[idx[1], idx[2]], pkgs, SUBSEP) > + > + if (ilen && !installedpkgs[idx[1]]) { > + for (i in pkgs) { > + print pkgs[i] > + } I think this means that if you have a foopkg archive for both i686 and x86_64 and foopkg is installed for x86_64, you aren't going to remove the i686 package (despite it clearly not being installed). > # enforce architecture match if specified > - if (!scanarch || scanarch == idx[2]) { > - count = split(packages[idx[1], idx[2]], pkgs, > SUBSEP) > + } else if (!scanarch || scanarch == idx[2]) { > for(i = 1; i <= count - keep; i++) { > print pkgs[i] > } > @@ -177,25 +189,26 @@ A flexible pacman cache cleaning utility. > Usage: ${myname} <operation> [options] [targets...] > > Operations: > - -d, --dryrun perform a dry run, only finding candidate packages. > - -m, --move <dir> move candidate packages to "dir". > - -r, --remove remove candidate packages. > + -d, --dryrun perform a dry run, only finding candidate > packages. > + -m, --move <dir> move candidate packages to "dir". > + -r, --remove remove candidate packages. > > Options: > - -a, --arch <arch> scan for "arch" (default: all architectures). > - -c, --cachedir <dir> scan "dir" for packages. can be used more than > once. > - (default: read from @sysconfdir@/pacman.conf). > - -f, --force apply force to mv(1) and rm(1) operations. > - -h, --help display this help message and exit. > - -i, --ignore <pkgs> ignore "pkgs", comma-separated. Alternatively, > specify > - "-" to read package names from stdin, newline- > - delimited. > - -k, --keep <num> keep "num" of each package in the cache (default: > 3). > - --nocolor remove color from output. > - -u, --uninstalled target uninstalled packages. > - -v, --verbose increase verbosity. specify up to 3 times. > - -z, --null use null delimiters for candidate names (only with > -v > - and -vv). > + -a, --arch <arch> scan for "arch" (default: all architectures). > + -c, --cachedir <dir> scan "dir" for packages. can be used more than > once. > + (default: read from @sysconfdir@/pacman.conf). > + -f, --force apply force to mv(1) and rm(1) operations. > + -h, --help display this help message and exit. > + -i, --ignore <pkgs> ignore "pkgs", comma-separated. Alternatively, > + specify "-" to read package names from stdin, > + newline-delimited. > + -k, --keep <num> keep "num" of each package in the cache > (default: 3) > + --nocolor remove color from output. > + --removeuninstalled removes every uninstalled package in the cache. > + -u, --uninstalled target uninstalled packages. > + -v, --verbose increase verbosity. specify up to 3 times. > + -z, --null use null delimiters for candidate names (only > with > + -v and -vv). > > EOF > } > @@ -207,7 +220,7 @@ version() { > > OPT_SHORT=':a:c:dfhi:k:m:rsuVvz' > OPT_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:' > 'move' > - 'nocolor' 'remove' 'uninstalled' 'version' 'verbose' 'null') > + 'nocolor' 'remove' 'removeuninstalled' 'uninstalled' 'version' > 'verbose' 'null') > > if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then > exit 1 > @@ -254,6 +267,8 @@ while :; do > shift ;; > -r|--remove) > delete=1 ;; > + --removeuninstalled) > + IFS=$'\n' read -r -d '' -a installedpkgs < <(pacman > -Qq) ;; > -u|--uninstalled) > IFS=$'\n' read -r -d '' -a ign < <(pacman -Qq) > blacklist+=("${ign[@]}") > @@ -318,7 +333,8 @@ for cachedir in "${cachedirs[@]}"; do > <(printf '%s\n' "$PWD"/*.pkg.tar?(.+([^.])) | pacsort --files | > pkgfilter "$keep" "$scanarch" \ > "${#whitelist[*]}" "${whitelist[@]}" \ > - "${#blacklist[*]}" "${blacklist[@]}") > + "${#blacklist[*]}" "${blacklist[@]}" \ > + "${#installedpkgs[*]}" "${installedpkgs[@]}") > > candidates+=("${cand[@]}") > unset cand > -- > 2.1.2
