Change get_disk_stats to always take a Unicode path, and work around os.statvfs not accepting Unicode paths. refs #2375
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
15dcab825a
commit
03d01fe81d
|
@ -352,7 +352,7 @@ class Server(unittest.TestCase):
|
|||
if 'cygwin' in syslow or 'windows' in syslow or 'darwin' in syslow:
|
||||
raise unittest.SkipTest("If your filesystem doesn't support efficient sparse files then it is very expensive (Mac OS X and Windows don't support efficient sparse files).")
|
||||
|
||||
avail = fileutil.get_available_space('.', 512*2**20)
|
||||
avail = fileutil.get_available_space(u".", 512*2**20)
|
||||
if avail <= 4*2**30:
|
||||
raise unittest.SkipTest("This test will spuriously fail if you have less than 4 GiB free on your filesystem.")
|
||||
|
||||
|
|
|
@ -536,11 +536,11 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
|
|||
self.failUnlessReallyEqual(fileutil.windows_expanduser(u"a\\~\\foo"), u"a\\~\\foo")
|
||||
|
||||
def test_disk_stats(self):
|
||||
avail = fileutil.get_available_space('.', 2**14)
|
||||
avail = fileutil.get_available_space(u".", 2**14)
|
||||
if avail == 0:
|
||||
raise unittest.SkipTest("This test will spuriously fail there is no disk space left.")
|
||||
|
||||
disk = fileutil.get_disk_stats('.', 2**13)
|
||||
disk = fileutil.get_disk_stats(u".", 2**13)
|
||||
self.failUnless(disk['total'] > 0, disk['total'])
|
||||
# we tolerate used==0 for a Travis-CI bug, see #2290
|
||||
self.failUnless(disk['used'] >= 0, disk['used'])
|
||||
|
@ -551,7 +551,7 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
|
|||
def test_disk_stats_avail_nonnegative(self):
|
||||
# This test will spuriously fail if you have more than 2^128
|
||||
# bytes of available space on your filesystem.
|
||||
disk = fileutil.get_disk_stats('.', 2**128)
|
||||
disk = fileutil.get_disk_stats(u".", 2**128)
|
||||
self.failUnlessEqual(disk['avail'], 0)
|
||||
|
||||
class PollMixinTests(unittest.TestCase):
|
||||
|
|
|
@ -452,6 +452,9 @@ def get_disk_stats(whichdir, reserved_space=0):
|
|||
filesystem as reserved_space.
|
||||
"""
|
||||
|
||||
if not isinstance(whichdir, unicode):
|
||||
raise AssertionError("whichdir must be Unicode")
|
||||
|
||||
if have_GetDiskFreeSpaceExW:
|
||||
# If this is a Windows system and GetDiskFreeSpaceExW is available, use it.
|
||||
# (This might put up an error dialog unless
|
||||
|
@ -475,7 +478,9 @@ def get_disk_stats(whichdir, reserved_space=0):
|
|||
# <http://docs.python.org/library/os.html#os.statvfs>
|
||||
# <http://opengroup.org/onlinepubs/7990989799/xsh/fstatvfs.html>
|
||||
# <http://opengroup.org/onlinepubs/7990989799/xsh/sysstatvfs.h.html>
|
||||
s = os.statvfs(whichdir)
|
||||
|
||||
from allmydata.util.encodingutil import get_filesystem_encoding
|
||||
s = os.statvfs(whichdir.encode(get_filesystem_encoding()))
|
||||
|
||||
# on my mac laptop:
|
||||
# statvfs(2) is a wrapper around statfs(2).
|
||||
|
|
Loading…
Reference in New Issue