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', time.time() - 1)
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))
58 e = index.BlankNewEntry("foo", now - 1)
59 e.from_stat(xstat.stat("foo"), now)
60 assert len(e.packed())
64 os.utime("foo", (-0x80000000, -0x80000000))
65 e = index.BlankNewEntry("foo", now - 1)
66 e.from_stat(xstat.stat("foo"), now)
67 assert len(e.packed())
78 fs = xstat.stat('tindex.py')
79 tmax = time.time() - 1
81 w1 = index.Writer('index.tmp', tmax)
89 w2 = index.Writer('index2.tmp', tmax)
90 w2.add('/a/b/n/2', fs)
94 w3 = index.Writer('index3.tmp', tmax)
95 w3.add('/a/c/n/3', fs)
104 r1all = [e.name for e in r1]
106 ['/a/b/x', '/a/b/c', '/a/b/', '/a/', '/'])
107 r2all = [e.name for e in r2]
109 ['/a/b/n/2', '/a/b/n/', '/a/b/', '/a/', '/'])
110 r3all = [e.name for e in r3]
112 ['/a/c/n/3', '/a/c/n/', '/a/c/', '/a/', '/'])
113 all = [e.name for e in index.merge(r2, r1, r3)]
115 ['/a/c/n/3', '/a/c/n/', '/a/c/',
116 '/a/b/x', '/a/b/n/2', '/a/b/n/', '/a/b/c',
117 '/a/b/', '/a/', '/'])
121 print [hex(e.flags) for e in r1]
122 WVPASSEQ([e.name for e in r1 if e.is_valid()], r1all)
123 WVPASSEQ([e.name for e in r1 if not e.is_valid()], [])
124 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()],
125 ['/a/c/n/3', '/a/c/n/', '/a/c/',
126 '/a/b/n/2', '/a/b/n/', '/a/b/', '/a/', '/'])
128 expect_invalid = ['/'] + r2all + r3all
129 expect_real = (set(r1all) - set(r2all) - set(r3all)) \
130 | set(['/a/b/n/2', '/a/c/n/3'])
131 dump(index.merge(r2, r1, r3))
132 for e in index.merge(r2, r1, r3):
133 print e.name, hex(e.flags), e.ctime
134 eiv = e.name in expect_invalid
135 er = e.name in expect_real
136 WVPASSEQ(eiv, not e.is_valid())
137 WVPASSEQ(er, e.is_real())
138 fake_validate(r2, r3)
139 dump(index.merge(r2, r1, r3))
140 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()], [])
142 e = eget(index.merge(r2, r1, r3), '/a/b/c')
145 dump(index.merge(r2, r1, r3))
146 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()],
147 ['/a/b/c', '/a/b/', '/a/', '/'])