[PATCH STABLE] windows: make win32 mandatory (issue1922)
Aaron Cohen
aaron at assonance.org
Thu Jan 20 12:59:47 CST 2011
Would using ctypes directly help?
Such as, for instance:
import ctypes
class FILETIME(ctypes.Structure):
_fields_ = [
('dwLowDateTime', ctypes.c_uint),
('dwHighDateTime', ctypes.c_uint),
]
class BY_HANDLE_FILE_INFORMATION(ctypes.Structure):
_fields_ = [
('dwFileAttributes', ctypes.c_uint),
('ftCreationTime', FILETIME),
('ftLastAccessTime', FILETIME),
('ftLastWriteTime', FILETIME),
('dwVolumeSerialNumber', ctypes.c_uint),
('nFileSizeHigh', ctypes.c_uint),
('nFileSizeLow', ctypes.c_uint),
('nNumberOfLinks', ctypes.c_uint),
('nFileIndexHigh', ctypes.c_uint),
('nFileIndexLow', ctypes.c_uint),
]
_GENERIC_READ = 0x80000000
_FILE_SHARE_READ = 0x00000001
_OPEN_EXISTING = 3
def _getfileinfo(pathname):
if isinstance(pathname, str):
#TODO: I'm not sure how mercurial likes to do this
pathname = unicode(pathname)
fh = ctypes.windll.kernel32.CreateFileW(pathname,
_GENERIC_READ, _FILE_SHARE_READ,
None, _OPEN_EXISTING, 0, None)
if fh == -1:
raise OSError(errno.ENOENT, 'The system cannot find the file specified')
info = BY_HANDLE_FILE_INFORMATION()
# TODO: Raise an appropriate exception if this returns true
ctypes.windll.kernel32.GetFileInformationByHandle(fh,
ctypes.pointer(info))
return info
def nlinks(pathname):
return _getfileinfo(pathname).nNumberOfLinks
More information about the Mercurial-devel
mailing list