From b4b4ef1168806c016fd7f0a07c5bb6d35dedf9a0 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 9 Jan 2010 21:17:10 -0500 Subject: [PATCH] A bunch of wvtests for the 'bup index' command. --- Makefile | 2 +- cmd-index.py | 31 ++++++++++++++++++++----------- cmd-tick.py | 17 +++++++++++++++++ t/test.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++++- wvtest.sh | 38 +++++++++++++++++++++++++++++--------- 5 files changed, 113 insertions(+), 22 deletions(-) create mode 100755 cmd-tick.py diff --git a/Makefile b/Makefile index 3209e8a..7c24fa1 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ endif default: all -all: bup-split bup-join bup-save bup-init bup-server bup-index \ +all: bup-split bup-join bup-save bup-init bup-server bup-index bup-tick \ bup randomgen chashsplit.so randomgen: randomgen.o diff --git a/cmd-index.py b/cmd-index.py index fd214f0..11699eb 100755 --- a/cmd-index.py +++ b/cmd-index.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2.5 -import sys, re, errno, stat, tempfile, struct, mmap +import sys, re, errno, stat, tempfile, struct, mmap, time import options, git from helpers import * @@ -34,10 +34,11 @@ class OsFile: class IxEntry: - def __init__(self, name, m, ofs): + def __init__(self, name, m, ofs, tstart): self._m = m self._ofs = ofs self.name = str(name) + self.tstart = tstart (self.dev, self.ctime, self.mtime, self.uid, self.gid, self.size, self.sha, self.flags) = struct.unpack(INDEX_SIG, buffer(m, ofs, ENTLEN)) @@ -68,7 +69,7 @@ class IxEntry: self.gid = st.st_gid self.size = st.st_size self.flags |= IX_EXISTS - if old != new: + if int(st.st_ctime) >= self.tstart or old != new: self.flags &= ~IX_HASHVALID return 1 # dirty else: @@ -108,12 +109,13 @@ class IndexReader: self.save() def __iter__(self): + tstart = int(time.time()) ofs = len(INDEX_HDR) while ofs < len(self.m): eon = self.m.find('\0', ofs) assert(eon >= 0) yield IxEntry(buffer(self.m, ofs, eon-ofs), - self.m, eon+1) + self.m, eon+1, tstart = tstart) ofs = eon + 1 + ENTLEN def save(self): @@ -267,7 +269,7 @@ def handle_path(ri, wi, dir, name, pst, xdev, can_delete_siblings): % os.path.realpath(p)) continue if stat.S_ISDIR(st.st_mode): - p += '/' + p = _slashappend(p) lds.append((p, st)) for p,st in reversed(sorted(lds)): dirty += handle_path(ri, wi, path, p, st, xdev, @@ -322,6 +324,12 @@ class MergeGetter: return self.cur +def _slashappend(s): + if s and not s.endswith('/'): + return s + '/' + else: + return s + def update_index(path): ri = IndexReader(indexfile) wi = IndexWriter(indexfile) @@ -337,8 +345,7 @@ def update_index(path): if rpath[-1] == '/': rpath = rpath[:-1] (dir, name) = os.path.split(rpath) - if dir and dir[-1] != '/': - dir += '/' + dir = _slashappend(dir) if stat.S_ISDIR(st.st_mode) and (not rpath or rpath[-1] != '/'): name += '/' can_delete_siblings = True @@ -407,9 +414,9 @@ xpaths = [] for path in extra: rp = os.path.realpath(path) st = os.lstat(rp) - if stat.S_ISDIR(st.st_mode) and not rp.endswith('/'): - rp += '/' - path += '/' + if stat.S_ISDIR(st.st_mode): + rp = _slashappend(rp) + path = _slashappend(path) xpaths.append((rp, path)) paths = [] @@ -427,7 +434,7 @@ if opt.update: update_index(rp) if opt['print'] or opt.status or opt.modified: - pi = iter(paths or [('/', '/')]) + pi = iter(paths or [(_slashappend(os.path.realpath('.')), '')]) (rpin, pin) = pi.next() for ent in IndexReader(indexfile): if ent.name < rpin: @@ -440,6 +447,8 @@ if opt['print'] or opt.status or opt.modified: if opt.modified and ent.flags & IX_HASHVALID: continue name = pin + ent.name[len(rpin):] + if not name: + name = '.' if opt.status: if not ent.flags & IX_EXISTS: print 'D ' + name diff --git a/cmd-tick.py b/cmd-tick.py new file mode 100755 index 0000000..da1d003 --- /dev/null +++ b/cmd-tick.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python2.5 +import sys, time +import options + +optspec = """ +bup tick +""" +o = options.Options('bup tick', optspec) +(opt, flags, extra) = o.parse(sys.argv[1:]) + +if extra: + log("bup tick: no arguments expected\n") + o.usage() + +t = time.time() +tleft = 1 - (t - int(t)) +time.sleep(tleft) diff --git a/t/test.sh b/t/test.sh index e40ada1..e736bf8 100755 --- a/t/test.sh +++ b/t/test.sh @@ -16,8 +16,53 @@ WVSTART "init" rm -rf "$BUP_DIR" WVPASS bup init -WVSTART "split" +WVSTART "index" +D=bupdata.tmp +rm -rf $D +mkdir $D +WVPASSEQ "$(bup index -p)" "" +WVPASSEQ "$(bup index -p $D)" "" +WVFAIL [ -e $D.fake ] +WVFAIL bup index -u $D.fake +WVPASS bup index -u $D +WVPASSEQ "$(bup index -p $D)" "$D/" +touch $D/a $D/b +mkdir $D/d $D/d/e +WVPASSEQ "$(bup index -s $D/)" "A $D/" +WVPASSEQ "$(bup index -s $D/b)" "" +bup tick +WVPASSEQ "$(bup index -us $D/b)" "A $D/b" +WVPASSEQ "$(bup index -us $D)" \ +"A $D/d/e/ +A $D/d/ +A $D/b +A $D/a +A $D/" +WVPASSEQ "$(bup index -us $D/b $D/a --fake-valid)" \ +" $D/b + $D/a" +WVPASSEQ "$(bup index -us $D/a)" " $D/a" # stays unmodified +touch $D/a +WVPASS bup index -u $D/a # becomes modified +WVPASSEQ "$(bup index -s $D)" \ +"A $D/d/e/ +A $D/d/ + $D/b +M $D/a +A $D/" +WVPASSEQ "$(cd $D && bup index -m .)" \ +"./d/e/ +./d/ +./a +./" +WVPASSEQ "$(cd $D && bup index -m)" \ +"d/e/ +d/ +a +." + +WVSTART "split" WVPASS bup split --bench -b tags1.tmp WVPASS bup split -vvvv -b testfile2 >tags2.tmp WVPASS bup split -t testfile2 >tags2t.tmp diff --git a/wvtest.sh b/wvtest.sh index 0ed5fb0..90bdc90 100644 --- a/wvtest.sh +++ b/wvtest.sh @@ -1,6 +1,3 @@ -WVIFS=" -" - # we don't quote $TEXT in case it contains newlines; newlines # aren't allowed in test output. However, we set -f so that # at least shell glob characters aren't processed. @@ -28,10 +25,7 @@ _wvcheck() WVPASS() { - #xIFS="$IFS" - #IFS="$WVIFS" TEXT="$*" - #IFS="$xIFS" if "$@"; then _wvcheck 0 "$TEXT" @@ -46,10 +40,7 @@ WVPASS() WVFAIL() { - #xIFS="$IFS" - #IFS="$WVIFS" TEXT="$*" - #IFS="$xIFS" if "$@"; then _wvcheck 1 "NOT($TEXT)" @@ -62,6 +53,35 @@ WVFAIL() } +_wvgetrv() +{ + ( "$@" >&2 ) + echo -n $? +} + + +WVPASSEQ() +{ + WVPASS [ "$#" -eq 2 ] + echo "Comparing:" >&2 + echo "$1" >&2 + echo "--" >&2 + echo "$2" >&2 + _wvcheck $(_wvgetrv [ "$1" = "$2" ]) "'$1' = '$2'" +} + + +WVPASSNE() +{ + WVPASS [ "$#" -eq 2 ] + echo "Comparing:" >&2 + echo "$1" >&2 + echo "--" >&2 + echo "$2" >&2 + _wvcheck $(_wvgetrv [ "$1" != "$2" ]) "'$1' != '$2'" +} + + WVSTART() { echo >&2 -- 2.39.2