From: Daira Hopwood Date: Thu, 5 Feb 2015 23:28:10 +0000 (+0000) Subject: Change get_disk_stats to always take a Unicode path, and work around os.statvfs not... X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=03d01fe81dae9b9f623f8b7d1e9339b859dec913;p=tahoe-lafs%2Ftahoe-lafs.git 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 --- diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index c63323ad..9692466c 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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.") diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index d907c118..a4dcbd8c 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -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): diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py index 74132733..e61d4461 100644 --- a/src/allmydata/util/fileutil.py +++ b/src/allmydata/util/fileutil.py @@ -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): # # # - 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).