Patchwork checklink: degrade gracefully on posix when fs is readonly (issue5511)

login
register
mail settings
Submitter Augie Fackler
Date May 21, 2017, 10:39 p.m.
Message ID <3bb12473b0f69a5f23c3.1495406381@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/20807/
State Accepted
Headers show

Comments

Augie Fackler - May 21, 2017, 10:39 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1495406188 14400
#      Sun May 21 18:36:28 2017 -0400
# Branch stable
# Node ID 3bb12473b0f69a5f23c384ef45b6d995d6a1c662
# Parent  99515353c72a4c54e4aac1a2ad4f8f724c7fdc9c
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.
Yuya Nishihara - May 22, 2017, 1:37 p.m.
On Sun, 21 May 2017 18:39:41 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1495406188 14400
> #      Sun May 21 18:36:28 2017 -0400
> # Branch stable
> # Node ID 3bb12473b0f69a5f23c384ef45b6d995d6a1c662
> # Parent  99515353c72a4c54e4aac1a2ad4f8f724c7fdc9c
> checklink: degrade gracefully on posix when fs is readonly (issue5511)

Looks good. Queued, thanks.

Patch

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -244,7 +244,17 @@  def checklink(path):
                 # 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: