# HG changeset patch # User Greg Ward # Date 2009-08-19 02:07:43 # Node ID 9ff178e7b627b7a52e2c0593306fddd043f0ef00 # Parent b8dc3eba4f9d1fd1ab8744240259d1ca84b233a9 tags: don't crash if unable to write tag cache This happens with hgweb in real life, if the httpd user is unable to write in the repository directory. Another case is doing 'hg incoming' on a repository in the filesystem owned by someone else. diff --git a/mercurial/tags.py b/mercurial/tags.py --- a/mercurial/tags.py +++ b/mercurial/tags.py @@ -301,7 +301,10 @@ def _readtagcache(ui, repo): 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): + 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 tags 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 +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,9 @@ acb14030fe0a21b60322c440ad2d20cf7685a376 tip 1:b9154636be93 first 0:acb14030fe0a b9154636be93 tip +% identify with cold cache +b9154636be93 tip +% identify with unwritable cache b9154636be93 tip % create a branch M a