From patchwork Sun Sep 23 20:36:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wisp3rwind X-Patchwork-Id: 790 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 6B73C713FDD8 for ; Sun, 23 Sep 2018 20:37:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on apollo X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00=-1,DKIM_SIGNED=0.1, MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,T_DKIM_INVALID=1 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Sun, 23 Sep 2018 20:37:17 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id DC0A6D9C71659; Sun, 23 Sep 2018 20:37:10 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Sun, 23 Sep 2018 20:37:10 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id BE16B2CA92; Sun, 23 Sep 2018 20:37:10 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=posteo.eu header.i=@posteo.eu header.b=SbGAchag Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id D3D442CA92 for ; Sun, 23 Sep 2018 20:37:06 +0000 (UTC) Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by luna.archlinux.org (Postfix) with ESMTPS for ; Sun, 23 Sep 2018 20:37:06 +0000 (UTC) Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 56E72210A2 for ; Sun, 23 Sep 2018 22:37:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.eu; s=2017; t=1537735025; bh=OIc5bMXKMBca5ESsRU0SEa9aJf3keQERH2q3S1gbBh0=; h=From:To:Cc:Subject:Date:From; b=SbGAchagVFPc7p9CgO+XdEFCm58JrorWQExUEWSYoZyOLzn058tri6n0qhhagox+x 9vjG9gN2qaVmrlji/B0R3hBZ8uw2YCNRHGx+8DZ9FXwXPm/rd6xqumjHLOw2X6uAtQ ZYyST8wP8vUB67ijxI13nZCfJI+EQ3rapBsevHuZbyJt5PfNQfAzittO341eVcAakR 54getsx6o3N/UsIv3VnWJ5cwkQlzdeqt8IVXjB+ZllLMFwkFjXl9TklhDzkLrDSMx+ UGhrJEmQtewxaQYVhumyEryHLNmq3DAzadGLnjgmm3r+mrl9l8Nmzej/5VCQKkTlAT ggQP9VE6xzemw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 42JJzN4Gl0z6tmb; Sun, 23 Sep 2018 22:37:04 +0200 (CEST) From: wisp3rwind To: pacman-contrib@lists.archlinux.org Subject: [PATCH v2] paccache: add --age-atime and --age-mtime options Date: Sun, 23 Sep 2018 22:36:05 +0200 Message-Id: <20180923203606.17704-1-wisp3rwind@posteo.eu> X-Mailer: git-send-email 2.19.0 In-Reply-To: <1537132261.yraaz6vtsy.astroid@hydrogen.kyriasis.com.none> References: <1537132261.yraaz6vtsy.astroid@hydrogen.kyriasis.com.none> MIME-Version: 1.0 X-BeenThere: pacman-contrib@lists.archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman-contrib development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-contrib-bounces@lists.archlinux.org Sender: "pacman-contrib" --- Hi, > So I would overall be okay with adding something like this, but there > are some changes I would want to have made first. First of all, is > there any specific case where you would need both supported? Because > only having mtime support sounds like it should be good enough? In fact, my usecase would only involve atime. mtime is probably not a very useful value, since it will usually be the date the package was built. The timestamp I'm actually interested in is installation time. Even for a `noatime`-mounted drive (where atime will be the download time), atime will be close to when the package was first installed. I agree that `--min-{a,m}time` is much more descriptive, changed that. @Eli: Thanks for the pointers at `touch`/`find`. I dropped my own parser in favor of invoking `date` (which uses the same parser as `touch`). However, because I want to combine the retention according to `--keep` and `--min-{a,m}time`, candidate selection cannot be done directly by `find`, but still needs to be done manually (in the awk script). Also, not creating a new `stat` process for every single file appears to improve performance of this feature quite a lot (subjectively, didn't benchmark). doc/paccache.8.txt | 5 ++++ src/paccache.sh.in | 61 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/doc/paccache.8.txt b/doc/paccache.8.txt index db81283..196bb49 100644 --- a/doc/paccache.8.txt +++ b/doc/paccache.8.txt @@ -38,6 +38,11 @@ Options Scan for packages for a specific architecture. Default is to scan for all architectures. +*\--min-atime *:: +*\--min-mtime *:: + Only consider packages for removal with atime respectively mtime older than + specified. The age can be given as '10d', '1m', '1y', '1y1m' etc. + *-c, \--cachedir *:: Specify a different cache directory. This option can be used more than once. Default is to use the cache directory configured in 'pacman.conf'. diff --git a/src/paccache.sh.in b/src/paccache.sh.in index 012ba9f..70e30e0 100644 --- a/src/paccache.sh.in +++ b/src/paccache.sh.in @@ -27,6 +27,7 @@ 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 min_atime=0 min_mtime=0 declare delim=$'\n' keep=3 movedir= scanarch= QUIET=0 @@ -45,13 +46,23 @@ pkgfilter() { # there's whitelist and blacklist parameters passed to this # script after the block of awk. - awk -v keep="$1" -v scanarch="$2" ' + awk -v keep="$1" -v scanarch="$2" -v min_atime="$3" -v min_mtime="$4" ' function basename(str) { sub(".*/", "", str); return str; } - function parse_filename(filename, parts, count, i, pkgname, arch) { + function parse_filename(filename, + atime, mtime, parts, count, i, pkgname, arch) { + + if (0 + min_atime + min_mtime != 0) { + # atime and mtime are in the first two columns and the + # separator is a single space + split(filename, parts, " ") + atime = parts[1] + mtime = parts[2] + filename = substr(filename, length(atime) + length(mtime) + 3) + } count = split(basename(filename), parts, "-") @@ -69,8 +80,12 @@ pkgfilter() { if ("" == packages[pkgname,arch]) { packages[pkgname,arch] = filename + atimes[pkgname,arch] = atime + mtimes[pkgname,arch] = mtime } else { packages[pkgname,arch] = packages[pkgname,arch] SUBSEP filename + atimes[pkgname,arch] = atimes[pkgname,arch] SUBSEP atime + mtimes[pkgname,arch] = mtimes[pkgname,arch] SUBSEP mtime } } @@ -101,12 +116,19 @@ pkgfilter() { # enforce architecture match if specified if (!scanarch || scanarch == idx[2]) { count = split(packages[idx[1], idx[2]], pkgs, SUBSEP) + split(atimes[idx[1], idx[2]], atime, SUBSEP) + split(mtimes[idx[1], idx[2]], mtime, SUBSEP) for(i = 1; i <= count - keep; i++) { - print pkgs[i] + # If checking file age, potentially keep more candidates + if ((0 + min_atime == 0 || (strtonum(atime[i]) < 0 + min_atime)) && + (0 + min_mtime == 0 || (strtonum(mtime[i]) < 0 + min_mtime)) \ + ) { + print pkgs[i] + } } } } - }' "${@:3}" + }' "${@:5}" } m4_include(../lib/size_to_human.sh) @@ -174,6 +196,12 @@ Usage: ${myname} [options] [targets...] -r, --remove remove candidate packages. Options: + --min-atime