obsolete: add seek to end of file before calling tell (issue3543)
authorAdrian Buehlmann <adrian@cadifra.com>
Mon, 16 Jul 2012 22:37:44 +0200
changeset 17195 48c232873a54
parent 17194 32a6a33b9a35
child 17196 2abe975ffb94
obsolete: add seek to end of file before calling tell (issue3543)
mercurial/obsolete.py
--- a/mercurial/obsolete.py	Fri Jul 13 21:52:37 2012 +0200
+++ b/mercurial/obsolete.py	Mon Jul 16 22:37:44 2012 +0200
@@ -51,7 +51,7 @@
   additional encoding. Keys cannot contain '\0' or ':' and values
   cannot contain '\0'.
 """
-import struct
+import os, struct
 from mercurial import util, base85
 from i18n import _
 
@@ -195,6 +195,12 @@
         if marker not in self._all:
             f = self.sopener('obsstore', 'ab')
             try:
+                # Whether the file's current position is at the begin or at
+                # the end after opening a file for appending is implementation
+                # defined. So we must seek to the end before calling tell(),
+                # or we may get a zero offset for non-zero sized files on
+                # some platforms (issue3543).
+                f.seek(0, os.SEEK_END)
                 offset = f.tell()
                 transaction.add('obsstore', offset)
                 if offset == 0: