# HG changeset patch # User Adrian Buehlmann # Date 2011-02-14 10:12:22 # 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')