Skip to content

Commit

Permalink
clean all: hint: ignore leftovers <= 64K. BZ 1645173
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmnks committed Feb 12, 2020
1 parent a84c70c commit 8289d47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
28 changes: 21 additions & 7 deletions cli.py
Expand Up @@ -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):
Expand All @@ -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]
Expand All @@ -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 '
Expand Down
9 changes: 6 additions & 3 deletions docs/yum.8
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8289d47

Please sign in to comment.