From: Rob Browning Date: Fri, 8 Nov 2013 00:33:43 +0000 (-0600) Subject: index.py: compute the index metadata offset more carefully. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=ada06e4653d6c50c6f4fe4def47684fe046c7305;p=packages%2Fb%2Fbup.git index.py: compute the index metadata offset more carefully. Previously when reading bupindex.meta (or similar), bup computed the metadata file offset for it's internal lookup table by just subtracting the size of a re-encoding of the metadata from file.tell() after the read. This works fine until we change the length of the metadata representation (which we just did); then bup will get the wrong length from the re-encoded data. To fix this, do what we should have done originally and capture the index metadata offset before reading the metadata via tell(), and use that instead. Thanks to Mark J Hewitt for being the first (known) victim and for helping track down the solution. Signed-off-by: Rob Browning --- diff --git a/lib/bup/index.py b/lib/bup/index.py index 1f3c777..09a3e62 100644 --- a/lib/bup/index.py +++ b/lib/bup/index.py @@ -58,10 +58,12 @@ class MetaStoreWriter: try: m_file.seek(0) try: + m_off = m_file.tell() m = metadata.Metadata.read(m_file) while m: m_encoded = m.encode() - self._offsets[m_encoded] = m_file.tell() - len(m_encoded) + self._offsets[m_encoded] = m_off + m_off = m_file.tell() m = metadata.Metadata.read(m_file) except EOFError: pass