# HG changeset patch # User Patrick Mezard # Date 2008-01-18 22:56:51 # Node ID cacfeee38870ddb8611ea79e5fa1352d920c1a63 # Parent 03ce5a919ae36ac5622562f5b3d06945c99d0340 util_win32: make os_link more robust (issue 761) On mapped drives, os_link() manages to create links but nlink() does not report them. diff --git a/mercurial/util_win32.py b/mercurial/util_win32.py --- a/mercurial/util_win32.py +++ b/mercurial/util_win32.py @@ -146,9 +146,18 @@ class WinOSError(WinError, OSError): self.win_strerror) def os_link(src, dst): - # NB will only succeed on NTFS try: win32file.CreateHardLink(dst, src) + # CreateHardLink sometimes succeeds on mapped drives but + # following nlinks() returns 1. Check it now and bail out. + if nlinks(src) < 2: + try: + win32file.DeleteFile(dst) + except: + pass + # Fake hardlinking error + raise WinOSError((18, 'CreateHardLink', 'The system cannot ' + 'move the file to a different disk drive')) except pywintypes.error, details: raise WinOSError(details)