##// END OF EJS Templates
posix: retry on symlink race in checklink...
Matt Mackall -
r26883:c750ed59 stable
parent child Browse files
Show More
@@ -170,6 +170,7 b' def checklink(path):'
170 """check whether the given path is on a symlink-capable filesystem"""
170 """check whether the given path is on a symlink-capable filesystem"""
171 # mktemp is not racy because symlink creation will fail if the
171 # mktemp is not racy because symlink creation will fail if the
172 # file already exists
172 # file already exists
173 while True:
173 name = tempfile.mktemp(dir=path, prefix='hg-checklink-')
174 name = tempfile.mktemp(dir=path, prefix='hg-checklink-')
174 try:
175 try:
175 fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-')
176 fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-')
@@ -177,15 +178,18 b' def checklink(path):'
177 os.symlink(os.path.basename(fd.name), name)
178 os.symlink(os.path.basename(fd.name), name)
178 os.unlink(name)
179 os.unlink(name)
179 return True
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
180 finally:
189 finally:
181 fd.close()
190 fd.close()
182 except AttributeError:
191 except AttributeError:
183 return False
192 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
189
193
190 def checkosfilename(path):
194 def checkosfilename(path):
191 '''Check that the base-relative path is a valid filename on this platform.
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