Patchwork D8512: manifest-cache: ignore IOError while writing

login
register
mail settings
Submitter phabricator
Date May 11, 2020, 7:27 a.m.
Message ID <differential-rev-PHID-DREV-jk3vslvt4r6bluunnqjv-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46295/
State Superseded
Headers show

Comments

phabricator - May 11, 2020, 7:27 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If the wcache directory is non writable for some reason (eg: belong to root).
  Trying to write to it currently crash Mercurial. Instead we ignore the error and
  skip writing that cache.
  
  We should probably improve the user experience of multiple users interacting
  with the same repository. However this is not an adventure for stable.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D8512

AFFECTED FILES
  mercurial/manifest.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1455,18 +1455,29 @@ 
         if not self._dirty or self._opener is None:
             return
         # rotate backwards to the first used node
-        with self._opener(
-            self._file, b'w', atomictemp=True, checkambig=True
-        ) as fp:
-            node = self._head.prev
-            while True:
-                if node.key in self._cache:
-                    fp.write(node.key)
-                    fp.write(struct.pack(b'>L', len(node.value)))
-                    fp.write(node.value)
-                if node is self._head:
-                    break
-                node = node.prev
+        try:
+            with self._opener(
+                self._file, b'w', atomictemp=True, checkambig=True
+            ) as fp:
+                node = self._head.prev
+                while True:
+                    if node.key in self._cache:
+                        fp.write(node.key)
+                        fp.write(struct.pack(b'>L', len(node.value)))
+                        fp.write(node.value)
+                    if node is self._head:
+                        break
+                    node = node.prev
+        except IOError:
+            # We could not write the cache (eg: permission error)
+            # the content can be missing.
+            #
+            # We could try harder and see if we could recreate a wcache
+            # directory were we coudl write too.
+            #
+            # XXX the error pass silently, having some way to issue an error
+            # log `ui.log` would be nice.
+            pass
 
     def __len__(self):
         if not self._read: