# HG changeset patch # User Patrick Mezard # Date 2010-08-19 20:51:09 # Node ID ccd8e592c3c54b94f26c895ae8bd49ed0b89c99e # Parent 50523b4407f638f8c58f709f23dfa95ea36ea0d1 win32: remove useless lstat() fallback in nlinks() The fallback was introduced by 3b4f05ff3130 at the same time than nlinks(). Apparently it only handles the case where target path does not exist. Just raise IOError directly. diff --git a/mercurial/win32.py b/mercurial/win32.py --- a/mercurial/win32.py +++ b/mercurial/win32.py @@ -34,20 +34,16 @@ def _getfileinfo(pathname): fh = win32file.CreateFile(pathname, win32file.GENERIC_READ, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, 0, None) - try: - return win32file.GetFileInformationByHandle(fh) - finally: - fh.Close() except pywintypes.error: - return None + raise OSError(errno.ENOENT, 'The system cannot find the file specified') + try: + return win32file.GetFileInformationByHandle(fh) + finally: + fh.Close() def nlinks(pathname): """Return number of hardlinks for the given file.""" - res = _getfileinfo(pathname) - if res is not None: - links = res[7] - else: - links = os.lstat(pathname).st_nlink + links = _getfileinfo(pathname)[7] if links < 2: # Known to be wrong for most network drives dirname = os.path.dirname(pathname) @@ -64,21 +60,15 @@ def samefile(fpath1, fpath2): guaranteed to work for files, not directories.""" res1 = _getfileinfo(fpath1) res2 = _getfileinfo(fpath2) - if res1 is not None and res2 is not None: - # Index 4 is the volume serial number, and 8 and 9 contain the file ID - return res1[4] == res2[4] and res1[8] == res2[8] and res1[9] == res2[9] - else: - return False + # Index 4 is the volume serial number, and 8 and 9 contain the file ID + return res1[4] == res2[4] and res1[8] == res2[8] and res1[9] == res2[9] def samedevice(fpath1, fpath2): """Returns whether fpath1 and fpath2 are on the same device. This is only guaranteed to work for files, not directories.""" res1 = _getfileinfo(fpath1) res2 = _getfileinfo(fpath2) - if res1 is not None and res2 is not None: - return res1[4] == res2[4] - else: - return False + return res1[4] == res2[4] def testpid(pid): '''return True if pid is still running or unable to