]> arthur.barton.de Git - bup.git/commitdiff
save-cmd: don't fail an assertion when doing a backup from the root level.
authorAvery Pennarun <apenwarr@gmail.com>
Wed, 3 Mar 2010 22:36:06 +0000 (17:36 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 3 Mar 2010 22:38:56 +0000 (17:38 -0500)
This wasn't caught by unit tests because "virtual" nodes added by
index.py:_golevel() weren't being marked as IX_EXISTS, which in the unit
tests included the root, so save-cmd was never actually trying to back up
that node.

That made the base directories incorrectly marked as status=D (deleted) if
you printed out the index during the tests.  So add a test for that to make
it fail if "/" is deleted (which obviously makes no sense), then add another
test for saving from the root level, then fix both bugs.

cmd/save-cmd.py
lib/bup/index.py
t/test.sh

index 0350fff2ffdf45f2b4a7daeee6bb22d38339f8f8..1abaa3e7f1a716400350663e49c23c881d59f90d 100755 (executable)
@@ -53,11 +53,14 @@ def _push(part):
     shalists.append([])
 
 def _pop(force_tree):
-    assert(len(parts) > 1)
+    assert(len(parts) >= 1)
     part = parts.pop()
     shalist = shalists.pop()
     tree = force_tree or w.new_tree(shalist)
-    shalists[-1].append(('40000', part, tree))
+    if shalists:
+        shalists[-1].append(('40000', part, tree))
+    else:  # this was the toplevel, so put it back for sanity
+        shalists.append(shalist)
     return tree
 
 lastremain = None
@@ -161,8 +164,9 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse):
             ent.validate(040000, newtree)
             ent.repack()
         count += ent.size
-        continue  
+        continue
 
+    # it's not a directory
     id = None
     if hashvalid:
         mode = '%o' % ent.gitmode
index 39cae888ed04cbf5ec04f12025314d7a469723be..d771592f0317f809fa1cf0f2fd69596feff10d2e 100644 (file)
@@ -41,6 +41,7 @@ def _golevel(level, f, ename, newentry):
     assert(level)
     while ename[:len(level.ename)] != level.ename:
         n = BlankNewEntry(level.ename[-1])
+        n.flags |= IX_EXISTS
         (n.children_ofs,n.children_n) = level.write(f)
         level.parent.list.append(n)
         level = level.parent
index b1ab48d633cfc4934eafc17fb31b55b2eb504943..512ddb6455c3c93853e07b29f67468dac8097f9a 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -97,7 +97,9 @@ tree1=$(bup save -t $D)
 WVPASSEQ "$(cd $D && bup index -m)" ""
 tree2=$(bup save -t $D)
 WVPASSEQ "$tree1" "$tree2"
-
+WVPASSEQ "$(bup index -s / | grep ^D)" ""
+tree3=$(bup save -t /)
+WVPASSEQ "$tree1" "$tree3"
 
 WVSTART "split"
 WVPASS bup split --bench -b <t/testfile1 >tags1.tmp