]> arthur.barton.de Git - bup.git/commitdiff
index.py: compute the index metadata offset more carefully.
authorRob Browning <rlb@defaultvalue.org>
Fri, 8 Nov 2013 00:33:43 +0000 (18:33 -0600)
committerRob Browning <rlb@defaultvalue.org>
Fri, 8 Nov 2013 00:40:15 +0000 (18:40 -0600)
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 <mjh@idnet.com> for being the first (known)
victim and for helping track down the solution.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/index.py

index 1f3c777c8ed9e804aa011b5b8773bc76f0b33334..09a3e628c8de9ee7d9d561ea7f3274d9f6ae525f 100644 (file)
@@ -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