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())
75 fs = xstat.stat('tindex.py')
77 w1 = index.Writer('index.tmp')
85 w2 = index.Writer('index2.tmp')
86 w2.add('/a/b/n/2', fs)
90 w3 = index.Writer('index3.tmp')
91 w3.add('/a/c/n/3', fs)
100 r1all = [e.name for e in r1]
102 ['/a/b/x', '/a/b/c', '/a/b/', '/a/', '/'])
103 r2all = [e.name for e in r2]
105 ['/a/b/n/2', '/a/b/n/', '/a/b/', '/a/', '/'])
106 r3all = [e.name for e in r3]
108 ['/a/c/n/3', '/a/c/n/', '/a/c/', '/a/', '/'])
109 all = [e.name for e in index.merge(r2, r1, r3)]
111 ['/a/c/n/3', '/a/c/n/', '/a/c/',
112 '/a/b/x', '/a/b/n/2', '/a/b/n/', '/a/b/c',
113 '/a/b/', '/a/', '/'])
117 print [hex(e.flags) for e in r1]
118 WVPASSEQ([e.name for e in r1 if e.is_valid()], r1all)
119 WVPASSEQ([e.name for e in r1 if not e.is_valid()], [])
120 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()],
121 ['/a/c/n/3', '/a/c/n/', '/a/c/',
122 '/a/b/n/2', '/a/b/n/', '/a/b/', '/a/', '/'])
124 expect_invalid = ['/'] + r2all + r3all
125 expect_real = (set(r1all) - set(r2all) - set(r3all)) \
126 | set(['/a/b/n/2', '/a/c/n/3'])
127 dump(index.merge(r2, r1, r3))
128 for e in index.merge(r2, r1, r3):
129 print e.name, hex(e.flags), e.ctime
130 eiv = e.name in expect_invalid
131 er = e.name in expect_real
132 WVPASSEQ(eiv, not e.is_valid())
133 WVPASSEQ(er, e.is_real())
134 fake_validate(r2, r3)
135 dump(index.merge(r2, r1, r3))
136 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()], [])
138 e = eget(index.merge(r2, r1, r3), '/a/b/c')
141 dump(index.merge(r2, r1, r3))
142 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()],
143 ['/a/b/c', '/a/b/', '/a/', '/'])