changeset 5879:cacfeee38870

util_win32: make os_link more robust (issue 761) On mapped drives, os_link() manages to create links but nlink() does not report them.
author Patrick Mezard <pmezard@gmail.com>
date Fri, 18 Jan 2008 23:56:51 +0100
parents 03ce5a919ae3
children b32a0596b2d7 f1ac41359b36
files mercurial/util_win32.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util_win32.py	Sat Jan 12 19:35:11 2008 +0100
+++ b/mercurial/util_win32.py	Fri Jan 18 23:56:51 2008 +0100
@@ -146,9 +146,18 @@
                          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)