FS#42482 - [paccache] No candidates should not be an error

Attached to Project: Pacman
Opened by Eric Schultz (schultzter) - Tuesday, 21 October 2014, 16:42 GMT
Last edited by Allan McRae (Allan) - Wednesday, 19 November 2014, 06:53 GMT
Task Type Feature Request
Category General
Status Closed
Assigned To No-one
Architecture All
Severity Low
Priority Normal
Reported Version 4.1.2
Due in Version 4.2.0
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Summary and Info:
I've created a little systemd timer unit that runs paccache on a regular basis to keep my cache clean. But a lot of the time it runs without finding any candidates and that results in an error condition. Normally that's fine. But when run from systemd it gets reported as a failure. So either no candidates should not be an error; or there should be a flag to indicate this is acceptable. Thanks,

Steps to Reproduce:
1. Create a systemd.service unit that runs paccache to clean-up the cache
2. Create a systemd.timer unit that regularly calls paccache service unit
3. Prune the cache so that next time the service runs there are no packages to prune
4. Check the status next time the service runs and it will show a failure (because there are no packages to remove)

This task depends upon

Closed by  Allan McRae (Allan)
Wednesday, 19 November 2014, 06:53 GMT
Reason for closing:  Fixed
Additional comments about closing:  git commit 566dc233570
Comment by Eric Schultz (schultzter) - Wednesday, 22 October 2014, 03:13 GMT
These are my unit files:

pacclean.service
[Unit]
Description=Clean-up package cache

[Service]
Type=oneshot
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/usr/bin/paccache -r
ExecStart=/usr/bin/paccache -ruk0

pacclean.timer
[Unit]
Description=Clean-up package cache

[Timer]
# run 5 minutes after boot time
OnBootSec=5min
# run 1 week after service was last started
OnUnitActiveSec=1w

[Install]
WantedBy=multi-user.target

And this is the result of systemctl status pacclean
● pacclean.service - Clean-up package cache
Loaded: loaded (/usr/local/lib/systemd/system/pacclean.service; static)
Active: failed (Result: exit-code) since Tue 2014-10-21 21:54:43 EDT; 1h 15min ago
Process: 1183 ExecStart=/usr/bin/paccache -r (code=exited, status=1/FAILURE)
Main PID: 1183 (code=exited, status=1/FAILURE)
Comment by Eric Schultz (schultzter) - Monday, 27 October 2014, 01:57 GMT
I've implemented the feature in paccache, and I've been using it locally without any issues. The modified paccache.sh.in file is attached, and here's the git diff:

diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
index 71aee23..eb04e69 100644
--- a/contrib/paccache.sh.in
+++ b/contrib/paccache.sh.in
@@ -24,7 +24,7 @@ declare -r myname='paccache'
declare -r myver='@PACKAGE_VERSION@'

declare -a cachedirs=() candidates=() cmdopts=() whitelist=() blacklist=()
-declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 verbose=0
+declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 noneisok=0 totalsaved=0 verbose=0
declare delim=$'\n' keep=3 movedir= scanarch=

USE_COLOR='y'
@@ -192,6 +192,8 @@ Usage: ${myname} <operation> [options] [targets...]
delimited.
-k, --keep <num> keep "num" of each package in the cache (default: 3).
--nocolor remove color from output.
+ -n, --noneisok do report an error if there are no candidates - use
+ when checking results in another script
-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
@@ -205,9 +207,9 @@ version() {
echo 'Copyright (C) 2011 Dave Reisner <dreisner@archlinux.org>'
}

-OPT_SHORT=':a:c:dfhi:k:m:rsuVvz'
+OPT_SHORT=':a:c:dfhi:k:m:nrsuVvz'
OPT_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:' 'move'
- 'nocolor' 'remove' 'uninstalled' 'version' 'verbose' 'null')
+ 'nocolor' 'noneisok' 'remove' 'uninstalled' 'version' 'verbose' 'null')

if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
exit 1
@@ -252,6 +254,8 @@ while :; do
-m|--move)
move=1 movedir=$2
shift ;;
+ -n|--noneisok)
+ noneisok=1 ;;
-r|--remove)
delete=1 ;;
-u|--uninstalled)
@@ -328,7 +332,11 @@ done

if (( ! ${#candidates[*]} )); then
msg 'no candidate packages found for pruning'
- exit 1
+ if (( noneisok )); then
+ exit 0
+ else
+ exit 1
+ fi
fi

# grab this prior to signature scavenging
Comment by Johannes Löthberg (demize) - Monday, 27 October 2014, 02:11 GMT
Send this to the pacman-dev ML if you want it in, patches in the bugtracker just hangs around with no progress.

Loading...