From 9872d84c87fa4034fad0e63a90fdc5c782dae88b Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 3 Mar 2010 17:36:06 -0500 Subject: [PATCH] save-cmd: don't fail an assertion when doing a backup from the root level. 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 | 10 +++++++--- lib/bup/index.py | 1 + t/test.sh | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index 0350fff..1abaa3e 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -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 diff --git a/lib/bup/index.py b/lib/bup/index.py index 39cae88..d771592 100644 --- a/lib/bup/index.py +++ b/lib/bup/index.py @@ -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 diff --git a/t/test.sh b/t/test.sh index b1ab48d..512ddb6 100755 --- 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 tags1.tmp -- 2.39.2