Permalink
Browse files

Oops, 'bup save /' produced an invalid tree.

Add a bunch of assertions to make sure that never happens.
  • Loading branch information...
1 parent 84c3d04 commit 609627e6d8ab41395c8bb06c7bffd1a500ee2916 @apenwarr apenwarr committed Jan 10, 2010
Showing with 12 additions and 5 deletions.
  1. +4 −2 cmd-save.py
  2. +7 −2 git.py
  3. +1 −1 t/test.sh
View
@@ -56,6 +56,7 @@ def eatslash(dir):
shalists = [[]]
def _push(part):
+ assert(part)
parts.append(part)
shalists.append([])
@@ -90,8 +91,9 @@ def _pop():
dirp = dir.split('/')
while parts > dirp:
_pop()
- for part in dirp[len(parts):]:
- _push(part)
+ if dir != '/':
+ for part in dirp[len(parts):]:
+ _push(part)
if not file:
# directory already handled.
View
9 git.py
@@ -200,8 +200,13 @@ def new_blob(self, blob):
def new_tree(self, shalist):
shalist = sorted(shalist, key = _shalist_sort_key)
- l = ['%s %s\0%s' % (mode,name,bin)
- for (mode,name,bin) in shalist]
+ l = []
+ for (mode,name,bin) in shalist:
+ assert(mode)
+ assert(mode[0] != '0')
+ assert(name)
+ assert(len(bin) == 20)
+ l.append('%s %s\0%s' % (mode,name,bin))
return self.maybe_write('tree', ''.join(l))
def _new_commit(self, tree, parent, author, adate, committer, cdate, msg):
View
@@ -94,7 +94,7 @@ WVSTART "save/fsck"
cd "$BUP_DIR" || exit 1
#git repack -Ad
#git prune
- (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master .) || WVFAIL
+ (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || WVFAIL
n=$(git fsck --full --strict 2>&1 |
egrep -v 'dangling (commit|tree)' |
tee -a /dev/stderr |

0 comments on commit 609627e

Please sign in to comment.