[PATCH 1 of 6 V2] win32: optimize parameters for the CreateFile call in _getfileinfo
Adrian Buehlmann
adrian at cadifra.com
Mon Feb 14 07:44:29 CST 2011
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1297678342 -3600
# Node ID 1c613c1ae43d756d6beecdd02283a7cea1dfe7ad
# Parent d4ab9486e514dd24e21a2ca3b6c439ea13d85cab
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
diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -31,8 +31,9 @@ def os_link(src, dst):
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')
More information about the Mercurial-devel
mailing list