3 from bup.helpers import *
4 import bup.xstat as xstat
9 cd = os.path.realpath('../../../t')
11 sd = os.path.realpath(cd + '/sampledata')
12 WVPASSEQ(index.realpath(cd + '/sampledata'), cd + '/sampledata')
13 WVPASSEQ(os.path.realpath(cd + '/sampledata/x'), sd + '/x')
14 WVPASSEQ(os.path.realpath(cd + '/sampledata/etc'), os.path.realpath('/etc'))
15 WVPASSEQ(index.realpath(cd + '/sampledata/etc'), sd + '/etc')
22 fs = xstat.stat('tindex.py')
23 w = index.Writer('index.tmp')
24 w.add('/var/tmp/sporky', fs)
25 w.add('/etc/passwd', fs)
33 print '%s%s %s' % (e.is_valid() and ' ' or 'M',
34 e.is_fake() and 'F' or ' ',
37 def fake_validate(*l):
40 e.validate(0100644, index.FAKE_SHA)
54 fs = xstat.stat('tindex.py')
56 w1 = index.Writer('index.tmp')
64 w2 = index.Writer('index2.tmp')
65 w2.add('/a/b/n/2', fs)
69 w3 = index.Writer('index3.tmp')
70 w3.add('/a/c/n/3', fs)
79 r1all = [e.name for e in r1]
81 ['/a/b/x', '/a/b/c', '/a/b/', '/a/', '/'])
82 r2all = [e.name for e in r2]
84 ['/a/b/n/2', '/a/b/n/', '/a/b/', '/a/', '/'])
85 r3all = [e.name for e in r3]
87 ['/a/c/n/3', '/a/c/n/', '/a/c/', '/a/', '/'])
88 all = [e.name for e in index.merge(r2, r1, r3)]
90 ['/a/c/n/3', '/a/c/n/', '/a/c/',
91 '/a/b/x', '/a/b/n/2', '/a/b/n/', '/a/b/c',
96 print [hex(e.flags) for e in r1]
97 WVPASSEQ([e.name for e in r1 if e.is_valid()], r1all)
98 WVPASSEQ([e.name for e in r1 if not e.is_valid()], [])
99 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()],
100 ['/a/c/n/3', '/a/c/n/', '/a/c/',
101 '/a/b/n/2', '/a/b/n/', '/a/b/', '/a/', '/'])
103 expect_invalid = ['/'] + r2all + r3all
104 expect_real = (set(r1all) - set(r2all) - set(r3all)) \
105 | set(['/a/b/n/2', '/a/c/n/3'])
106 dump(index.merge(r2, r1, r3))
107 for e in index.merge(r2, r1, r3):
108 print e.name, hex(e.flags), e.ctime
109 eiv = e.name in expect_invalid
110 er = e.name in expect_real
111 WVPASSEQ(eiv, not e.is_valid())
112 WVPASSEQ(er, e.is_real())
113 fake_validate(r2, r3)
114 dump(index.merge(r2, r1, r3))
115 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()], [])
117 e = eget(index.merge(r2, r1, r3), '/a/b/c')
120 dump(index.merge(r2, r1, r3))
121 WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()],
122 ['/a/b/c', '/a/b/', '/a/', '/'])