From 8289d47465135f0b04e974949c8a3c6f27558d8c Mon Sep 17 00:00:00 2001 From: Michal Domonkos Date: Mon, 14 Jan 2019 16:10:14 +0100 Subject: [PATCH] clean all: hint: ignore leftovers <= 64K. BZ 1645173 This prevents the hint from showing all the time due to the fact that directories (and some files such as productid) are never cleaned up automatically. --- cli.py | 28 +++++++++++++++++++++------- docs/yum.8 | 9 ++++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/cli.py b/cli.py index 102c31d1..5118ec2b 100755 --- a/cli.py +++ b/cli.py @@ -1771,6 +1771,7 @@ def cleanCli(self, userlist): paths = glob.glob(cacheglob + '/*') table = ([], [], [], []) # (enabled, disabled, untracked, other) repos = self.repos.repos + empty = True for path in paths: base = os.path.basename(path) if os.path.isdir(path): @@ -1785,8 +1786,22 @@ def cleanCli(self, userlist): # Ordinary file (such as timedhosts) col = 3 usage = yum.misc.disk_usage(path) - if usage > 0: - table[col].append((usage, path)) + if not usage: + continue + table[col].append((usage, path)) + # Detect any uncleaned data. + # + # We never remove directories or any unrecognized repodata + # files, so there always will be a few kilobytes left behind. + # To avoid a constant false alarm, let's ignore such files if + # they are really tiny (such as "productid"). The easiest way + # is to look at "usage" as it covers both directories and + # files. Given that a typical cleaned repodir (4K) consists of + # the gen/ (4K) and packages/ (4K) subdirs and possibly the + # productid file (8K), let's "round" it up to 64K and use that + # as our threshold. + if col < 3 and usage > 64*1024: + empty = False # Print the table (verbose mode only) lines = [_('Disk usage under %s after cleanup:') % cacheglob] @@ -1811,12 +1826,11 @@ def cleanCli(self, userlist): msg = '\n'.join(lines) self.verbose_logger.log(yum.logginglevels.DEBUG_3, msg) - # Print a short hint for leftover repos specifically (non-verbose - # mode only) - total = sum(totals[:3]) - if self.conf.debuglevel == 6 or not total: + # Print a short hint if leftover repos are found (non-verbose mode + # only). + if empty or self.conf.debuglevel == 6: return code, [] - total = self.format_number(total) + total = self.format_number(sum(totals[:3])) if total[-1] == ' ': total = total[:-1] + 'bytes' msg = (_('Other repos take up %s of disk space ' diff --git a/docs/yum.8 b/docs/yum.8 index b67d150b..94454973 100644 --- a/docs/yum.8 +++ b/docs/yum.8 @@ -1036,10 +1036,10 @@ The following are the ways which you can invoke \fByum\fP in clean mode. Note that these commands only operate on the currently enabled repositories within the current \fBcachedir\fR (that is, with any substitution variables such as $releasever expanded to their runtime values). -For more control over which repositories are cleaned, you can use -\fB\-\-enablerepo\fP, \fB\-\-disablerepo\fP and \fB\-\-releasever\fP. +To clean specific repositories, use \fB\-\-enablerepo\fP, \fB\-\-disablerepo\fP +or \fB\-\-releasever\fP accordingly. Note, however, that untracked (no longer configured) repositories cannot be -cleaned this way and have to be removed manually. +cleaned this way; they have to be removed manually. .IP "\fByum clean expire-cache\fP" Eliminate the local data saying when the metadata and mirrorlists were downloaded for each repo. This means yum will revalidate the cache for each repo. next time it is used. However if the cache is still valid, nothing significant was deleted. @@ -1073,6 +1073,9 @@ As a convenience, if this command does not result in a completely empty cache due to the restrictions outlined at the beginning of this section, a message will be printed, saying how much disk space can be reclaimed by cleaning the remaining repos manually. +For this purpose, a repo is considered clean when its disk usage doesn't exceed +64KB (that is to account for directory entries and tiny metadata files such as +"productid" that are never cleaned). .SH "EXAMPLES" .PP