]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Change get_disk_stats to always take a Unicode path, and work around os.statvfs not...
authorDaira Hopwood <daira@jacaranda.org>
Thu, 5 Feb 2015 23:28:10 +0000 (23:28 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 24 Feb 2015 16:57:00 +0000 (16:57 +0000)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/test/test_storage.py
src/allmydata/test/test_util.py
src/allmydata/util/fileutil.py

index c63323ad59ca33071030da0e4631d0bf400ad77a..9692466cbb261a27a230397dbd5b2c7b179acbf3 100644 (file)
@@ -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.")
 
index d907c118a76341abb39bb7f1183368ed8d2f41b9..a4dcbd8cf63d7b09f3ae49ba24fcec77e394b600 100644 (file)
@@ -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):
index 74132733169f306f8feb668f565d547f9b6f4df9..e61d44615142e9c34e9b780f20aa06eff0e6df9f 100644 (file)
@@ -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).