From 5fefb7bce27b7642d4410f2f09c7891ca4378c9e Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Tue, 4 Jun 2013 13:40:54 +0000 Subject: S7904: add method for finding bytes free in path This has no tests, as the ability to run them requires root privilidges or a more recent kernel and user namespace support. --- morphlib/util.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'morphlib/util.py') diff --git a/morphlib/util.py b/morphlib/util.py index 6d15fcfe..007c7f7c 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -13,6 +13,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import os import re import morphlib @@ -219,3 +220,9 @@ def copyfileobj(inputfp, outputfp, blocksize=1024*1024): # pragma: no cover elif sparse: outputfp.seek(-1, os.SEEK_CUR) outputfp.write("\x00") + +def get_bytes_free_in_path(path): # pragma: no cover + """Returns the bytes free in the filesystem that path is part of""" + + fsinfo = os.statvfs(path) + return fsinfo.f_bavail * fsinfo.f_bsize -- cgit v1.2.1