]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/util/fileutil.py
Improved error handling and cosmetics for ctypes calls on Windows.
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / util / fileutil.py
index 1133c261c7f54b14652c3a4d7516c872cf30a809..185e3fa44aeafea7503ac86b0d33c71cb747a2fd 100644 (file)
@@ -11,6 +11,11 @@ if sys.platform == "win32":
         create_unicode_buffer, get_last_error
     from ctypes.wintypes import BOOL, DWORD, LPCWSTR, LPWSTR, LPVOID, HANDLE
 
+if sys.platform == "win32":
+    from ctypes import WINFUNCTYPE, WinError, windll, POINTER, byref, c_ulonglong, \
+        create_unicode_buffer, get_last_error
+    from ctypes.wintypes import BOOL, DWORD, LPCWSTR, LPWSTR
+
 from twisted.python import log
 
 from pycryptopp.cipher.aes import AES
@@ -546,8 +551,12 @@ if sys.platform == "win32":
 
     # <http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/4465cafb-f4ed-434f-89d8-c85ced6ffaa8/>
     def flush_volume(path):
-        drive = os.path.splitdrive(os.path.realpath(path))[0]
+        abspath = os.path.realpath(path)
+        if abspath.startswith("\\\\?\\"):
+            abspath = abspath[4 :]
+        drive = os.path.splitdrive(abspath)[0]
 
+        print "flushing %r" % (drive,)
         hVolume = CreateFileW(u"\\\\.\\" + drive,
                               GENERIC_WRITE,
                               FILE_SHARE_READ | FILE_SHARE_WRITE,