summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-04-12 20:33:45 +0200
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-07-14 22:06:07 +0200
commit87ffa0b3d1342c6832632d392e6ac857f1831dd4 (patch)
tree2003c35a9fef7de29f29150bdbe9d1f23e348956
parentUse self.config instead self.core.config + inverted getConfig with getConf (diff)
downloadpyload-87ffa0b3d1342c6832632d392e6ac857f1831dd4.tar.xz
fs_bsize support
-rw-r--r--module/utils.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/module/utils.py b/module/utils.py
index 94bf78054..424aeaf37 100644
--- a/module/utils.py
+++ b/module/utils.py
@@ -117,12 +117,25 @@ def freeSpace(folder):
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))
return free_bytes.value
else:
- from os import statvfs
-
- s = statvfs(folder)
+ s = os.statvfs(folder)
return s.f_bsize * s.f_bavail
+def fs_bsize(path):
+ """ get optimal file system buffer size (in bytes) for I/O calls """
+ path = fs_encode(path)
+
+ if os.name == "nt":
+ import ctypes
+
+ drive = "%s\\" % os.path.splitdrive(path)[0]
+ cluster_sectors, sector_size = ctypes.c_longlong(0)
+ ctypes.windll.kernel32.GetDiskFreeSpaceW(ctypes.c_wchar_p(drive), ctypes.pointer(cluster_sectors), ctypes.pointer(sector_size), None, None)
+ return cluster_sectors * sector_size
+ else:
+ return os.statvfs(path).f_bsize
+
+
def uniqify(seq, idfun=None):
# order preserving
if idfun is None: