4 from bup.helpers import *
5 import bup.xstat as xstat
10 cd = os.path.realpath('../../../t')
12 sd = os.path.realpath(cd + '/sampledata')
13 WVPASSEQ(index.realpath(cd + '/sampledata'), cd + '/sampledata')
14 WVPASSEQ(os.path.realpath(cd + '/sampledata/x'), sd + '/x')
15 WVPASSEQ(os.path.realpath(cd + '/sampledata/etc'), os.path.realpath('/etc'))
16 WVPASSEQ(index.realpath(cd + '/sampledata/etc'), sd + '/etc')
23 fs = xstat.stat('tindex.py')
24 w = index.Writer('index.tmp')
25 w.add('/var/tmp/sporky', fs)
26 w.add('/etc/passwd', fs)
34 print '%s%s %s' % (e.is_valid() and ' ' or 'M',
35 e.is_fake() and 'F' or ' ',
38 def fake_validate(*l):
41 e.validate(0100644, index.FAKE_SHA)
50 def index_negative_timestamps():
56 os.utime("foo", (-86400, -86400))
57 e = index.BlankNewEntry("foo")
58 e.from_stat(xstat.stat("foo"), time.time())
59 assert len(e.packed())
63 os.utime("foo", (-0x80000000, -0x80000000))
64 e = index.BlankNewEntry("foo")
65 e.from_stat(xstat.stat("foo"), time.time())
66 assert len(e.packed())
77 fs = xstat.stat('tindex.py')
79 w1 = index.Writer('index.tmp')
87 w2 = index.Writer('index2.tmp')
88 w2.add('/a/b/n/2', fs)
92 w3 = index.Writer('index3.tmp')
93 w3.add('/a/c/n/3', fs)
102 r1all = [e.name for e in r1]
104 ['/a/b/x', '/a/b/c', '/a/b/', '/a/', '/'])
105 r2all = [e.name for e in r2]
107 ['/a/b/n/2', '/a/b/n/', '/a/b/', '/a/', '/'])
108 r3all = [e.name for e in r3]
110 ['/a/c/n/3', '/a/c/n/', '/a/c/', '/a/', '/'])
111 all = [e.name for e in index.merge(r2, r1, r3)]
113 ['/a/c/n/3', '/a/c/n/', '/a/c/',
114 '/a/b/x', '/a/b/n/2', '/a/b/n/', '/a/b/c',
115 '/a/b/', '/a/', '/'])
119 print [hex(e.flags) for e in r1]
120 WVPASSEQ([e.name for e in r1 if e.is_valid()], r1all)
121 WVPASSEQ([e.name for e in r1 if not e.is_valid()], [])
122 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()],
123 ['/a/c/n/3', '/a/c/n/', '/a/c/',
124 '/a/b/n/2', '/a/b/n/', '/a/b/', '/a/', '/'])
126 expect_invalid = ['/'] + r2all + r3all
127 expect_real = (set(r1all) - set(r2all) - set(r3all)) \
128 | set(['/a/b/n/2', '/a/c/n/3'])
129 dump(index.merge(r2, r1, r3))
130 for e in index.merge(r2, r1, r3):
131 print e.name, hex(e.flags), e.ctime
132 eiv = e.name in expect_invalid
133 er = e.name in expect_real
134 WVPASSEQ(eiv, not e.is_valid())
135 WVPASSEQ(er, e.is_real())
136 fake_validate(r2, r3)
137 dump(index.merge(r2, r1, r3))
138 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()], [])
140 e = eget(index.merge(r2, r1, r3), '/a/b/c')
143 dump(index.merge(r2, r1, r3))
144 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()],
145 ['/a/b/c', '/a/b/', '/a/', '/'])