From: Daira Hopwood Date: Mon, 18 May 2015 00:42:01 +0000 (+0100) Subject: fileutil.py: use ctypes.get_last_error() instead of GetLastError(). refs #1531 X-Git-Tag: allmydata-tahoe-1.10.1a1~4 X-Git-Url: https://git.rkrishnan.org/vdrive/%5B/%5D%20/uri/(%5B%5E?a=commitdiff_plain;h=143af6151800efd8ecb750e682aa42da254ce5a7;p=tahoe-lafs%2Ftahoe-lafs.git fileutil.py: use ctypes.get_last_error() instead of GetLastError(). refs #1531 Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py index 0349669e..20f5c34e 100644 --- a/src/allmydata/util/fileutil.py +++ b/src/allmydata/util/fileutil.py @@ -363,23 +363,27 @@ def to_windows_long_path(path): have_GetDiskFreeSpaceExW = False if sys.platform == "win32": - from ctypes import WINFUNCTYPE, windll, POINTER, byref, c_ulonglong, create_unicode_buffer + from ctypes import WINFUNCTYPE, windll, POINTER, byref, c_ulonglong, create_unicode_buffer, \ + get_last_error from ctypes.wintypes import BOOL, DWORD, LPCWSTR, LPWSTR - # - GetLastError = WINFUNCTYPE(DWORD)(("GetLastError", windll.kernel32)) - # - GetEnvironmentVariableW = WINFUNCTYPE(DWORD, LPCWSTR, LPWSTR, DWORD)( - ("GetEnvironmentVariableW", windll.kernel32)) + GetEnvironmentVariableW = WINFUNCTYPE( + DWORD, + LPCWSTR, LPWSTR, DWORD, + use_last_error=True + )(("GetEnvironmentVariableW", windll.kernel32)) try: # PULARGE_INTEGER = POINTER(c_ulonglong) # - GetDiskFreeSpaceExW = WINFUNCTYPE(BOOL, LPCWSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER)( - ("GetDiskFreeSpaceExW", windll.kernel32)) + GetDiskFreeSpaceExW = WINFUNCTYPE( + BOOL, + LPCWSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER, + use_last_error=True + )(("GetDiskFreeSpaceExW", windll.kernel32)) have_GetDiskFreeSpaceExW = True except Exception: @@ -424,7 +428,7 @@ def windows_getenv(name): n = GetEnvironmentVariableW(name, None, 0) # GetEnvironmentVariableW returns DWORD, so n cannot be negative. if n == 0: - err = GetLastError() + err = get_last_error() if err == ERROR_ENVVAR_NOT_FOUND: return None raise OSError("Windows error %d attempting to read size of environment variable %r" @@ -437,7 +441,7 @@ def windows_getenv(name): buf = create_unicode_buffer(u'\0'*n) retval = GetEnvironmentVariableW(name, buf, n) if retval == 0: - err = GetLastError() + err = get_last_error() if err == ERROR_ENVVAR_NOT_FOUND: return None raise OSError("Windows error %d attempting to read environment variable %r" @@ -484,7 +488,7 @@ def get_disk_stats(whichdir, reserved_space=0): byref(n_free_for_root)) if retval == 0: raise OSError("Windows error %d attempting to get disk statistics for %r" - % (GetLastError(), whichdir)) + % (get_last_error(), whichdir)) free_for_nonroot = n_free_for_nonroot.value total = n_total.value free_for_root = n_free_for_root.value