]> arthur.barton.de Git - bup.git/commitdiff
Fix a bug where marginally old files couldn't be stored in the index
authorTim Hatch <tim@timhatch.com>
Sat, 16 Apr 2011 00:18:51 +0000 (17:18 -0700)
committerTim Hatch <tim@timhatch.com>
Sat, 16 Apr 2011 00:21:27 +0000 (17:21 -0700)
Due to the struct having unsigned timestamps, files with dates between Dec 13,
1901 and Jan 1, 1970 were not representable.  This change extends the struct to
be able to pack signed timestamps, which was the spirit of code in _fixup, and
extends the useful range back to 1901. Timestamps prior to 1901 are still
adjusted to zero, as they were before.

There should be no compatibility problems loading packed structures created
before this change, since positive values were truncated at 0x7fffffff.

Signed-off-by: Tim Hatch <tim@timhatch.com>
lib/bup/index.py
lib/bup/t/tindex.py

index 4900786263f90b1a3730a5887bce868d3ef382ee..0007bbc02c31023fb309446219447b20eaca79c2 100644 (file)
@@ -8,7 +8,7 @@ INDEX_HDR = 'BUPI\0\0\0\2'
 # FIXME: guess I should have used 64-bit integers to store the mtime/ctime.
 # NTFS mtime=0 corresponds to the year 1600, which can't be stored in a 32-bit
 # time_t.  Next time we update the bupindex format, keep that in mind.
-INDEX_SIG = '!IIIIIQII20sHII'
+INDEX_SIG = '!IiiIIQII20sHII'
 
 ENTLEN = struct.calcsize(INDEX_SIG)
 FOOTER_SIG = '!Q'
index 4b9e16ab2da7c3bd06db481c3fb25dda62729e3e..5d7f02d3bc7b340f6049d6bc7cac94902b1f34ae 100644 (file)
@@ -1,4 +1,5 @@
 import os
+import time
 from bup import index
 from bup.helpers import *
 import bup.xstat as xstat
@@ -45,6 +46,26 @@ def eget(l, ename):
         if e.name == ename:
             return e
 
+@wvtest
+def index_negative_timestamps():
+    # Makes 'foo' exist
+    f = file('foo', 'wb')
+    f.close()
+
+    # Dec 31, 1969
+    os.utime("foo", (-86400, -86400))
+    e = index.BlankNewEntry("foo")
+    e.from_stat(xstat.stat("foo"), time.time())
+    assert len(e.packed())
+    WVPASS()
+
+    # Jun 10, 1893
+    os.utime("foo", (-0x90000000, -0x90000000))
+    e = index.BlankNewEntry("foo")
+    e.from_stat(xstat.stat("foo"), time.time())
+    assert len(e.packed())
+    WVPASS()
+
 
 @wvtest
 def index_dirty():