summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngelos Evripiotis <jevripiotis@bloomberg.net>2019-04-02 13:36:56 +0100
committerAngelos Evripiotis <jevripiotis@bloomberg.net>2019-06-12 11:45:19 +0100
commit91178bdf105db358a025ce36de1231f76875f3be (patch)
tree44e02fd5e4b3ba1db29cbdce804ae5d0df51569b
parent64750a1f74e9fb6cb01d6ffbe5ca3aab1cddbaaf (diff)
downloadbuildstream-91178bdf105db358a025ce36de1231f76875f3be.tar.gz
utils._get_volume_size: use shutil.disk_usageaevri/psutil_volume
This is win32-friendly, less to read, and fixes a latent bug. Avoid dealing with low-level platform specifics by using the higher-level shutil.disk_usage() function to calc total and available bytes for us. shutil is also more correct - it uses f_frsize to convert from blocks to bytes, instead of f_bsize. I verified that the numbers match with the output from `df -k`, whereas the old implementation did not. Here are the meanings from `man statvfs`: f_frsize The size in bytes of the minimum unit of allocation on this file system. (This corresponds to the f_bsize member of struct statfs.) f_bsize The preferred length of I/O requests for files on this file system. (Corresponds to the f_iosize member of struct statfs.) Link to shutil.disk_usage() implementation: https://github.com/python/cpython/blob/3.5/Lib/shutil.py#L980
-rw-r--r--src/buildstream/utils.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index f509ce998..775a11142 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -642,12 +642,11 @@ def _get_dir_size(path):
#
def _get_volume_size(path):
try:
- stat_ = os.statvfs(path)
+ usage = shutil.disk_usage(path)
except OSError as e:
raise UtilError("Failed to retrieve stats on volume for path '{}': {}"
.format(path, e)) from e
-
- return stat_.f_bsize * stat_.f_blocks, stat_.f_bsize * stat_.f_bavail
+ return usage.total, usage.free
# _parse_size():