##// END OF EJS Templates
posix: retry on symlink race in checklink...
Matt Mackall -
r26883:c750ed59 stable
parent child Browse files
Show More
@@ -170,22 +170,26 b' def checklink(path):'
170 170 """check whether the given path is on a symlink-capable filesystem"""
171 171 # mktemp is not racy because symlink creation will fail if the
172 172 # file already exists
173 name = tempfile.mktemp(dir=path, prefix='hg-checklink-')
174 try:
175 fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-')
173 while True:
174 name = tempfile.mktemp(dir=path, prefix='hg-checklink-')
176 175 try:
177 os.symlink(os.path.basename(fd.name), name)
178 os.unlink(name)
179 return True
180 finally:
181 fd.close()
182 except AttributeError:
183 return False
184 except OSError as inst:
185 # sshfs might report failure while successfully creating the link
186 if inst[0] == errno.EIO and os.path.exists(name):
187 os.unlink(name)
188 return False
176 fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-')
177 try:
178 os.symlink(os.path.basename(fd.name), name)
179 os.unlink(name)
180 return True
181 except OSError as inst:
182 # link creation might race, try again
183 if inst[0] == errno.EEXIST:
184 continue
185 # sshfs might report failure while successfully creating the link
186 if inst[0] == errno.EIO and os.path.exists(name):
187 os.unlink(name)
188 return False
189 finally:
190 fd.close()
191 except AttributeError:
192 return False
189 193
190 194 def checkosfilename(path):
191 195 '''Check that the base-relative path is a valid filename on this platform.
General Comments 0
You need to be logged in to leave comments. Login now