[PATCH] tags: don't crash if unable to write tag cache

Greg Ward greg-hg at gerg.ca
Tue Aug 18 21:08:14 CDT 2009


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1250647663 14400
# Node ID 53d6e68f1674899b24e2e9b5603a0425cd5117ac
# Parent  fa32759d6c076606699a8bb8add24f9de3375655
tags: don't crash if unable to write tag cache

(This can happen with hgweb in real life, if the httpd user is unable to
write in the repository directory.)

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -301,7 +301,12 @@
 
 def _writetagcache(ui, repo, heads, tagfnode, cachetags):
 
-    cachefile = repo.opener('tags.cache', 'w', atomictemp=True)
+    try:
+        cachefile = repo.opener('tags.cache', 'w', atomictemp=True)
+    except (OSError, IOError), err:
+        ui.warn(_('unable to write tag cache in %s: %s\n')
+                % (repo.path, err.strerror))
+        return
     _debug(ui, 'writing cache file %s\n' % cachefile.name)
 
     realheads = repo.heads()            # for sanity checks below
diff --git a/tests/test-tags b/tests/test-tags
--- a/tests/test-tags
+++ b/tests/test-tags
@@ -37,9 +37,17 @@
 hg identify
 
 # repeat with cold tag cache
+echo "% identify with cold cache"
 rm -f .hg/tags.cache
 hg identify
 
+# and again, but now unable to write tag cache
+echo "% identify with unwritable cache"
+rm -f .hg/tags.cache
+chmod 555 .hg
+hg identify 2>&1 | sed "s|$HGTMP|*HGTMP*|"
+chmod 755 .hg
+
 echo "% create a branch"
 echo bb > a
 hg status
diff --git a/tests/test-tags.out b/tests/test-tags.out
--- a/tests/test-tags.out
+++ b/tests/test-tags.out
@@ -13,6 +13,10 @@
 tip                                1:b9154636be93
 first                              0:acb14030fe0a
 b9154636be93 tip
+% identify with cold cache
+b9154636be93 tip
+% identify with unwritable cache
+unable to write tag cache in *HGTMP*/test-tags/t/.hg: Permission denied
 b9154636be93 tip
 % create a branch
 M a


More information about the Mercurial-devel mailing list