Skip to content

Commit

Permalink
clean all: really calculate disk usage
Browse files Browse the repository at this point in the history
While we mention "disk usage" in the related messages and docs, we
display apparent size of the files instead of actual disk usage.  This
commit fixes that (produces the same output as the du(1) tool).
  • Loading branch information
dmnks committed Feb 12, 2020
1 parent c06a5ce commit dacf35c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 2 additions & 5 deletions cli.py
Expand Up @@ -1781,18 +1781,15 @@ def cleanCli(self, userlist):
col = 0
else:
col = 1
# Recursively gather all files in this repodir
files = yum.misc.getFileList(path, '', [])
else:
# Ordinary file (such as timedhosts)
col = 3
files = [path]
usage = sum(map(os.path.getsize, files))
usage = yum.misc.disk_usage(path)
if usage > 0:
table[col].append((usage, path))

# Print the table (verbose mode only)
lines = [_('Disk usage of %s after cleanup:') % cacheglob]
lines = [_('Disk usage under %s after cleanup:') % cacheglob]
headers = ('enabled repos', 'disabled repos', 'untracked repos',
'other data')
totals = [0, 0, 0, 0]
Expand Down
12 changes: 12 additions & 0 deletions yum/misc.py
Expand Up @@ -1310,3 +1310,15 @@ def validate_repoid(repoid):
return char
else:
return None

def disk_usage(path):
"""Return disk usage of the given filename, recursively for dirs."""
def usage(path):
return os.stat(path).st_blocks * 512
total = usage(path)
if not os.path.isdir(path):
return total
for root, dirs, files in os.walk(path):
paths = (os.path.join(root, entry) for entry in dirs + files)
total += sum(usage(path) for path in paths)
return total

0 comments on commit dacf35c

Please sign in to comment.