Use win32file.CreateFileW instead of CreateFile since even though the docs for win32file claim that CreateFile supports unicode paths, it actually does not, as it uses the C++ CreateFile underneath via encoding to mbcs

This commit is contained in:
Kovid Goyal 2014-11-22 07:45:42 +05:30
parent 584e427b72
commit 1b506eefb2

View File

@ -209,7 +209,7 @@ def windows_get_fileid(path):
if isbytestring(path): if isbytestring(path):
path = path.decode(filesystem_encoding) path = path.decode(filesystem_encoding)
try: try:
h = win32file.CreateFile(path, 0, 0, None, win32file.OPEN_EXISTING, h = win32file.CreateFileW(path, 0, 0, None, win32file.OPEN_EXISTING,
win32file.FILE_FLAG_BACKUP_SEMANTICS, 0) win32file.FILE_FLAG_BACKUP_SEMANTICS, 0)
try: try:
data = win32file.GetFileInformationByHandle(h) data = win32file.GetFileInformationByHandle(h)
@ -261,7 +261,9 @@ def windows_get_size(path):
not in the directory entry (which could be out of date). So we open the not in the directory entry (which could be out of date). So we open the
file, and get the actual size. ''' file, and get the actual size. '''
import win32file import win32file
h = win32file.CreateFile( if isbytestring(path):
path = path.decode(filesystem_encoding)
h = win32file.CreateFileW(
path, 0, win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE | win32file.FILE_SHARE_DELETE, path, 0, win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE | win32file.FILE_SHARE_DELETE,
None, win32file.OPEN_EXISTING, 0, None) None, win32file.OPEN_EXISTING, 0, None)
try: try:
@ -297,7 +299,9 @@ def windows_hardlink(src, dest):
def windows_nlinks(path): def windows_nlinks(path):
import win32file import win32file
dwFlagsAndAttributes = win32file.FILE_FLAG_BACKUP_SEMANTICS if os.path.isdir(path) else 0 dwFlagsAndAttributes = win32file.FILE_FLAG_BACKUP_SEMANTICS if os.path.isdir(path) else 0
handle = win32file.CreateFile(path, win32file.GENERIC_READ, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, dwFlagsAndAttributes, None) if isbytestring(path):
path = path.decode(filesystem_encoding)
handle = win32file.CreateFileW(path, win32file.GENERIC_READ, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, dwFlagsAndAttributes, None)
try: try:
return win32file.GetFileInformationByHandle(handle)[7] return win32file.GetFileInformationByHandle(handle)[7]
finally: finally:
@ -343,7 +347,7 @@ class WindowsAtomicFolderMove(object):
pass pass
try: try:
h = win32file.CreateFile(f, win32file.GENERIC_READ, h = win32file.CreateFileW(f, win32file.GENERIC_READ,
win32file.FILE_SHARE_DELETE, None, win32file.FILE_SHARE_DELETE, None,
win32file.OPEN_EXISTING, win32file.FILE_FLAG_SEQUENTIAL_SCAN, 0) win32file.OPEN_EXISTING, win32file.FILE_FLAG_SEQUENTIAL_SCAN, 0)
except error as e: except error as e: