[PATCH 2 of 3] cache: safer handling of failing seek when writing revision branch cache

Mads Kiilerich mads at kiilerich.com
Sat Mar 12 20:13:30 EST 2016


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1457831182 -3600
#      Sun Mar 13 02:06:22 2016 +0100
# Node ID b8a5abd4a18ee070b922d03e5c14d63df504b78a
# Parent  c4e1d65a90e115650d0de52a403e9fcb2170d410
cache: safer handling of failing seek when writing revision branch cache

If the seek for some reason fails (perhaps because the file is too short to
search to the requested position), make sure we seek to the start and rewrite
everything.

It is unknown if this fixes a real problem that ever happened.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -482,6 +482,9 @@ class revbranchcache(object):
                 if f.tell() != start:
                     repo.ui.debug("truncating %s to %s\n" % (_rbcrevs, start))
                     f.seek(start)
+                    if f.tell() != start:
+                        start = 0
+                        f.seek(start)
                     f.truncate()
                 end = revs * _rbcrecsize
                 f.write(self._rbcrevs[start:end])


More information about the Mercurial-devel mailing list