utils._get_volume_size: use shutil.disk_usage

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

Edited by Angelos Evripiotis

Merge request reports

Loading