checklink: degrade gracefully on posix when fs is readonly (issue5511)
authorAugie Fackler <augie@google.com>
Sun, 21 May 2017 18:36:28 -0400
changeset 32394 38a2b9d90131
parent 32393 d47b62368f3a
child 32395 24245b54aa8a
checklink: degrade gracefully on posix when fs is readonly (issue5511) In the unlucky case, checklink tries to make a new file for the symlink test to target. If the filesystem is readonly (perhaps due to permissions in a repo owned by someone else) we just report the filesystem as not supporting symlinks, since the user probably can't write anyway.
mercurial/posix.py
--- a/mercurial/posix.py	Fri May 19 20:14:31 2017 -0700
+++ b/mercurial/posix.py	Sun May 21 18:36:28 2017 -0400
@@ -244,7 +244,17 @@
                 # create a fixed file to link to; doesn't matter if it
                 # already exists.
                 target = 'checklink-target'
-                open(os.path.join(cachedir, target), 'w').close()
+                try:
+                    open(os.path.join(cachedir, target), 'w').close()
+                except IOError as inst:
+                    if inst[0] == errno.EACCES:
+                        # If we can't write to cachedir, just pretend
+                        # that the fs is readonly and by association
+                        # that the fs won't support symlinks. This
+                        # seems like the least dangerous way to avoid
+                        # data loss.
+                        return False
+                    raise
             try:
                 os.symlink(target, name)
                 if cachedir is None: