]> arthur.barton.de Git - bup.git/commitdiff
A bunch of wvtests for the 'bup index' command.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 10 Jan 2010 02:17:10 +0000 (21:17 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 10 Jan 2010 02:17:10 +0000 (21:17 -0500)
Makefile
cmd-index.py
cmd-tick.py [new file with mode: 0755]
t/test.sh
wvtest.sh

index 3209e8a98a8334ef4d9084f5aea2e6724ca88b6b..7c24fa1fbd950047af51667310745cfa8f272178 100644 (file)
--- 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
index fd214f05cbad9a5b53ce72fdc10202171e4ca042..11699ebc8df174b4f93875b29c774526d02af746 100755 (executable)
@@ -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 (executable)
index 0000000..da1d003
--- /dev/null
@@ -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)
index e40ada1d788edc765888f0247fc09290285666ca..e736bf81768531681760e332c0b5f9c0f0f5f543 100755 (executable)
--- 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 <testfile1 >tags1.tmp
 WVPASS bup split -vvvv -b testfile2 >tags2.tmp
 WVPASS bup split -t testfile2 >tags2t.tmp
index 0ed5fb0cdadb541ffc2e6a0847429c86907a4da0..90bdc909b5e34a625ad2d3729b7277a5d38da67f 100644 (file)
--- 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