win32: optimize parameters for the CreateFile call in _getfileinfo
Set dwDesiredAccess to 0 instead of GENERIC_READ.
Zero is enough for querying the file metadata. We don't even need to
access the -contents- of the file.
Set dwShareMode to FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
instead of the overly restrictive FILE_SHARE_READ.
There is no need to cause write or delete accesses by other processes to
fail while we are querying file metadata.
See http://msdn.microsoft.com/en-us/library/
aa363858(v=vs.85).aspx
--- a/mercurial/win32.py Thu Feb 10 13:46:28 2011 -0600
+++ b/mercurial/win32.py Mon Feb 14 11:12:22 2011 +0100
@@ -31,8 +31,9 @@
def _getfileinfo(pathname):
"""Return number of hardlinks for the given file."""
try:
- fh = win32file.CreateFile(pathname,
- win32file.GENERIC_READ, win32file.FILE_SHARE_READ,
+ fh = win32file.CreateFile(pathname, 0,
+ win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE |
+ win32file.FILE_SHARE_DELETE,
None, win32file.OPEN_EXISTING, 0, None)
except pywintypes.error:
raise OSError(errno.ENOENT, 'The system cannot find the file specified')