Mercurial > hg
comparison mercurial/win32.py @ 13374:1c613c1ae43d
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
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Mon, 14 Feb 2011 11:12:22 +0100 |
parents | 2ef915184ff2 |
children | f1fa8f481c7c |
comparison
equal
deleted
inserted
replaced
13368:d4ab9486e514 | 13374:1c613c1ae43d |
---|---|
29 raise OSError(errno.EINVAL, 'Hardlinking not supported') | 29 raise OSError(errno.EINVAL, 'Hardlinking not supported') |
30 | 30 |
31 def _getfileinfo(pathname): | 31 def _getfileinfo(pathname): |
32 """Return number of hardlinks for the given file.""" | 32 """Return number of hardlinks for the given file.""" |
33 try: | 33 try: |
34 fh = win32file.CreateFile(pathname, | 34 fh = win32file.CreateFile(pathname, 0, |
35 win32file.GENERIC_READ, win32file.FILE_SHARE_READ, | 35 win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE | |
36 win32file.FILE_SHARE_DELETE, | |
36 None, win32file.OPEN_EXISTING, 0, None) | 37 None, win32file.OPEN_EXISTING, 0, None) |
37 except pywintypes.error: | 38 except pywintypes.error: |
38 raise OSError(errno.ENOENT, 'The system cannot find the file specified') | 39 raise OSError(errno.ENOENT, 'The system cannot find the file specified') |
39 try: | 40 try: |
40 return win32file.GetFileInformationByHandle(fh) | 41 return win32file.GetFileInformationByHandle(fh) |