comparison mercurial/util_win32.py @ 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 60bd4e707a7d
children f1ac41359b36 0973501e5f4a
comparison
equal deleted inserted replaced
5852:03ce5a919ae3 5879:cacfeee38870
144 WinError.__init__(self, err) 144 WinError.__init__(self, err)
145 OSError.__init__(self, self.winerror_map.get(self.win_errno, 0), 145 OSError.__init__(self, self.winerror_map.get(self.win_errno, 0),
146 self.win_strerror) 146 self.win_strerror)
147 147
148 def os_link(src, dst): 148 def os_link(src, dst):
149 # NB will only succeed on NTFS
150 try: 149 try:
151 win32file.CreateHardLink(dst, src) 150 win32file.CreateHardLink(dst, src)
151 # CreateHardLink sometimes succeeds on mapped drives but
152 # following nlinks() returns 1. Check it now and bail out.
153 if nlinks(src) < 2:
154 try:
155 win32file.DeleteFile(dst)
156 except:
157 pass
158 # Fake hardlinking error
159 raise WinOSError((18, 'CreateHardLink', 'The system cannot '
160 'move the file to a different disk drive'))
152 except pywintypes.error, details: 161 except pywintypes.error, details:
153 raise WinOSError(details) 162 raise WinOSError(details)
154 163
155 def nlinks(pathname): 164 def nlinks(pathname):
156 """Return number of hardlinks for the given file.""" 165 """Return number of hardlinks for the given file."""