[pacman-dev] [PATCH v4] paccache: adding the possibility for multiple cachedirs
Either by specifing several -c parameters or only one -c parameter with a comma separated value. One could for example be for the official arch packages and one for the aur. Signed-off-by: Maxim Andersson <thesilentboatman@gmail.com> --- contrib/paccache.sh.in | 92 +++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in index 039ac8a..6c6c27f 100644 --- a/contrib/paccache.sh.in +++ b/contrib/paccache.sh.in @@ -23,9 +23,9 @@ shopt -s extglob declare -r myname='paccache' declare -r myver='@PACKAGE_VERSION@' -declare -a candidates=() cmdopts=() whitelist=() blacklist=() +declare -a cachedirs=() candidates=() cmdopts=() whitelist=() blacklist=() declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 verbose=0 -declare cachedir=@localstatedir@/cache/pacman/pkg delim=$'\n' keep=3 movedir= scanarch= +declare delim=$'\n' keep=3 movedir= scanarch= USE_COLOR='y' @@ -133,13 +133,13 @@ summarize() { [[ $pkg =~ $pkg_re ]] && name=${BASH_REMATCH[1]} arch=${BASH_REMATCH[2]} if [[ -z $seen || $seenarch != "$arch" || $seen != "$name" ]]; then seen=$name seenarch=$arch - printf '%s (%s):\n' "$name" "$arch" + printf '%s (%s):\n' "${name##*/}" "$arch" fi - printf ' %s\n' "$pkg" + printf ' %s\n' "${pkg##*/}" elif (( verbose >= 2 )); then - printf "$PWD/%s$delim" "$pkg" - else printf "%s$delim" "$pkg" + else + printf "%s$delim" "${pkg##*/}" fi done < <(printf '%s\n' "$@" | pacsort --files) fi @@ -159,25 +159,25 @@ 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. - (default: @localstatedir@/cache/pacman/pkg). - -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 <dirs> scan "dirs" for packages, comma-separated. + (default: @localstatedir@/cache/pacman/pkg). + -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, + pecify "-" 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). EOF } @@ -203,7 +203,9 @@ while :; do scanarch=$2 shift ;; -c|--cachedir) - cachedir=$2 + IFS=',' read -r -a dirs <<< "$2" + cachedirs+=("${dirs[@]}") + unset dirs shift ;; -d|--dryrun) dryrun=1 ;; @@ -256,6 +258,9 @@ done m4_include(../scripts/library/term_colors.sh) +# setting default cachedir +cachedirs=("${cachedirs[@]:-@localstatedir@/cache/pacman/pkg}") + # remaining args are a whitelist whitelist=("$@") @@ -265,28 +270,39 @@ case $(( dryrun+delete+move )) in [^1]) die "only one operation may be used at a time" ;; esac -[[ -d $cachedir ]] || - die "cachedir '%s' does not exist or is not a directory" "$cachedir" - [[ $movedir && ! -d $movedir ]] && die "destination directory '%s' does not exist or is not a directory" "$movedir" if (( move || delete )); then # make it an absolute path since we're about to chdir - [[ ${movedir:0:1} != '/' ]] && movedir=$PWD/$movedir - [[ ! -w $cachedir || ( $movedir && ! -w $movedir ) ]] && needsroot=1 + [[ $movedir && ${movedir:0:1} != '/' ]] && movedir=$PWD/$movedir + [[ $movedir && ! -w $movedir ]] && needsroot=1 fi -# unlikely that this will fail, but better make sure -cd "$cachedir" >/dev/null || die "failed to chdir to '%s'" "$cachedir" +for cachedir in "${cachedirs[@]}"; do + [[ -d $cachedir ]] || + die "cachedir '%s' does not exist or is not a directory" "$cachedir" + + if (( move || delete )); then + [[ ! -w $cachedir ]] && needsroot=1 + fi + + # unlikely that this will fail, but better make sure + pushd "$cachedir" &>/dev/null || die "failed to chdir to '%s'" "$cachedir" + + # note that these results are returned in an arbitrary order from awk, but + # they'll be resorted (in summarize) iff we have a verbosity level set. + IFS=$'\n' read -r -d '' -a cand < \ + <(printf '%s\n' "$PWD"/*.pkg.tar?(.+([^.])) | pacsort --files | + pkgfilter "$keep" "$scanarch" \ + "${#whitelist[*]}" "${whitelist[@]}" \ + "${#blacklist[*]}" "${blacklist[@]}") -# note that these results are returned in an arbitrary order from awk, but -# they'll be resorted (in summarize) iff we have a verbosity level set. -IFS=$'\n' read -r -d '' -a candidates < \ - <(printf '%s\n' *.pkg.tar?(.+([^.])) | pacsort --files | - pkgfilter "$keep" "$scanarch" \ - "${#whitelist[*]}" "${whitelist[@]}" \ - "${#blacklist[*]}" "${blacklist[@]}") + candidates+=("${cand[@]}") + unset cand + + popd &>/dev/null +done if (( ! ${#candidates[*]} )); then msg 'no candidate packages found for pruning' -- 2.0.3
Why is the dir list comma-separated? The standard for *nix is to separate paths with a colon. On 08/27/2014 05:12 PM, Maxim Andersson wrote:
Either by specifing several -c parameters or only one -c parameter with a comma separated value. One could for example be for the official arch packages and one for the aur.
Signed-off-by: Maxim Andersson <thesilentboatman@gmail.com>
On Wed, Aug 27, 2014 at 06:09:37PM +0400, Yanus Poluektovich wrote:
Why is the dir list comma-separated? The standard for *nix is to separate paths with a colon.
In environment variables, sure. Do you have an example of where this is done in a command line argument? I'm actually reconsidering my stance on the feature entirely, as it disallows cachedirs with legitimate "," characters in them. I think maybe it's sufficient to just accept multiple -c arguments (a feature which isn't actually documented anywhere but in the commit message and code). d
On 08/27/2014 07:55 PM, Dave Reisner wrote:
On Wed, Aug 27, 2014 at 06:09:37PM +0400, Yanus Poluektovich wrote:
Why is the dir list comma-separated? The standard for *nix is to separate paths with a colon.
In environment variables, sure. Do you have an example of where this is done in a command line argument?
Hmmm. Off the top of my head I can remember one — java -cp argument.
I'm actually reconsidering my stance on the feature entirely, as it disallows cachedirs with legitimate "," characters in them. I think maybe it's sufficient to just accept multiple -c arguments (a feature which isn't actually documented anywhere but in the commit message and code).
d
On Wed, Aug 27, 2014 at 08:02:49PM +0400, Yanus Poluektovich wrote:
On 08/27/2014 07:55 PM, Dave Reisner wrote:
On Wed, Aug 27, 2014 at 06:09:37PM +0400, Yanus Poluektovich wrote:
Why is the dir list comma-separated? The standard for *nix is to separate paths with a colon.
In environment variables, sure. Do you have an example of where this is done in a command line argument?
Hmmm. Off the top of my head I can remember one — java -cp argument.
Java is a really poor choice to argue with. Command line flags to Java look almost nothing like those in other *nix programs. At times, it even appears inconsistent with itself. For example: -Xmx10G -XX:+CycleTime -XX:AdaptiveSizePolicyWeight=50 These are most similar to "long options", but use a single dash which is the syntax used by "short options". The latter 2 also appear to use a ":" character to separate the flag name from its value, rather than the more commonly found "=" found in *nix flags. d
2014-08-27 17:55 GMT+02:00 Dave Reisner <d@falconindy.com>:
On Wed, Aug 27, 2014 at 06:09:37PM +0400, Yanus Poluektovich wrote:
Why is the dir list comma-separated? The standard for *nix is to separate paths with a colon.
In environment variables, sure. Do you have an example of where this is done in a command line argument?
I'm actually reconsidering my stance on the feature entirely, as it disallows cachedirs with legitimate "," characters in them. I think maybe it's sufficient to just accept multiple -c arguments (a feature which isn't actually documented anywhere but in the commit message and code).
I feel it would be enough with multiple -c arguments. I added the comma-separated option so it would behave similar to the -i argument. If the comma-separated list is removed, should there be a note about the multiple -c option in the usage function?
d
On Wed, Aug 27, 2014 at 08:58:22PM +0200, Maxim Andersson wrote:
2014-08-27 17:55 GMT+02:00 Dave Reisner <d@falconindy.com>:
On Wed, Aug 27, 2014 at 06:09:37PM +0400, Yanus Poluektovich wrote:
Why is the dir list comma-separated? The standard for *nix is to separate paths with a colon.
In environment variables, sure. Do you have an example of where this is done in a command line argument?
I'm actually reconsidering my stance on the feature entirely, as it disallows cachedirs with legitimate "," characters in them. I think maybe it's sufficient to just accept multiple -c arguments (a feature which isn't actually documented anywhere but in the commit message and code).
I feel it would be enough with multiple -c arguments. I added the comma-separated option so it would behave similar to the -i argument.
I understand the rationale, but remember that "," is invalid in a package name (arguments to -i). Meanwhile, it's entirely valid for a path (arguments to -c).
If the comma-separated list is removed, should there be a note about the multiple -c option in the usage function?
Should probably be there regardless. d
2014-08-27 21:15 GMT+02:00 Dave Reisner <d@falconindy.com>:
On Wed, Aug 27, 2014 at 08:58:22PM +0200, Maxim Andersson wrote:
2014-08-27 17:55 GMT+02:00 Dave Reisner <d@falconindy.com>:
On Wed, Aug 27, 2014 at 06:09:37PM +0400, Yanus Poluektovich wrote:
Why is the dir list comma-separated? The standard for *nix is to separate paths with a colon.
In environment variables, sure. Do you have an example of where this is done in a command line argument?
I'm actually reconsidering my stance on the feature entirely, as it disallows cachedirs with legitimate "," characters in them. I think maybe it's sufficient to just accept multiple -c arguments (a feature which isn't actually documented anywhere but in the commit message and code).
I feel it would be enough with multiple -c arguments. I added the comma-separated option so it would behave similar to the -i argument.
I understand the rationale, but remember that "," is invalid in a package name (arguments to -i). Meanwhile, it's entirely valid for a path (arguments to -c).
Yes, it's bad if paccache breaks when using a valid (but somewhat strange) path. I've removed the comma-separated option and updated usage() in a new patch. I also aligned the nocolor-option with the other long options in usage() and remove some leading whitespaces in parse_filename().
If the comma-separated list is removed, should there be a note about the multiple -c option in the usage function?
Should probably be there regardless.
d
participants (3)
-
Dave Reisner
-
Maxim Andersson
-
Yanus Poluektovich