# HG changeset patch # User Matt Mackall # Date 2013-07-28 20:02:32 # Node ID cfdae231ba781a590e2e27b3eeee4dabda884be5 # Parent 9e8298a324accd509cd8df1915cd98dfbdcdb512 checklink: work around sshfs brain-damage (issue3636) With the follow_symlinks option, sshfs will successfully create links while claiming it encountered an I/O error. In addition, depending on the type of link, it may subsequently be impossible to delete the link via sshfs. Our existing link to '.' will cause sshfs to think the link is a directory, and thus cause unlink to give EISDIR. Links to non-existent names or circular links will cause the created link to not even be visible. Thus, we need to create a new temporary file and link to that. We'll still get a failure, but we'll be able to remove the link. diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -154,10 +154,16 @@ def checklink(path): # file already exists name = tempfile.mktemp(dir=path, prefix='hg-checklink-') try: - os.symlink(".", name) + fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-') + os.symlink(os.path.basename(fd.name), name) os.unlink(name) return True - except (OSError, AttributeError): + except AttributeError: + return False + except OSError, inst: + # sshfs might report failure while successfully creating the link + if inst[0] == errno.EIO and os.path.exists(name): + os.unlink(name) return False def checkosfilename(path):