From a63f1c9245df11397ad11fd00f27e96244ee0adf Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 25 Jun 2010 13:13:49 -0400 Subject: [PATCH] vfs: correctly handle reading small files. After the recent change to let vfs seek around in files, we broke support for files that were only one chunk. Fix it up, then add some unit tests to detect such mistakes in the future. Also, 'bup ftp' now returns nonzero if it catches any exceptions during execution, making it more suitable for use in scripts... such as the unit tests :) Signed-off-by: Avery Pennarun --- cmd/ftp-cmd.py | 7 +++++++ lib/bup/vfs.py | 2 +- t/test.sh | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/ftp-cmd.py b/cmd/ftp-cmd.py index 7c2823f..c6f26af 100755 --- a/cmd/ftp-cmd.py +++ b/cmd/ftp-cmd.py @@ -125,6 +125,7 @@ git.check_repo_or_die() top = vfs.RefList(None) pwd = top +rv = 0 if extra: lines = extra @@ -156,6 +157,7 @@ for line in lines: write_to_file(pwd.resolve(parm).open(), sys.stdout) elif cmd == 'get': if len(words) not in [2,3]: + rv = 1 raise Exception('Usage: get [localname]') rname = words[1] (dir,base) = os.path.split(rname) @@ -175,13 +177,18 @@ for line in lines: write_to_file(inf, outf) outf.close() except Exception, e: + rv = 1 log(' error: %s\n' % e) elif cmd == 'help' or cmd == '?': log('Commands: ls cd pwd cat get mget help quit\n') elif cmd == 'quit' or cmd == 'exit' or cmd == 'bye': break else: + rv = 1 raise Exception('no such command %r' % cmd) except Exception, e: + rv = 1 log('error: %s\n' % e) #raise + +sys.exit(rv) diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py index c8f688a..ea33818 100644 --- a/lib/bup/vfs.py +++ b/lib/bup/vfs.py @@ -88,7 +88,7 @@ class _ChunkReader: self.blob = None else: self.it = None - self.blob = cp().get(hash.encode('hex')) + self.blob = ''.join(cp().join(hash.encode('hex')))[startofs:] def next(self, size): out = '' diff --git a/t/test.sh b/t/test.sh index 007f745..6398236 100755 --- a/t/test.sh +++ b/t/test.sh @@ -26,8 +26,10 @@ WVFAIL [ -e $D.fake ] WVFAIL bup index --check -u $D.fake WVPASS bup index --check -u $D WVPASSEQ "$(bup index --check -p $D)" "$D/" -touch $D/a $D/b $D/f +touch $D/a +bup random 128k >$D/b mkdir $D/d $D/d/e +bup random 512 >$D/f WVPASSEQ "$(bup index -s $D/)" "A $D/" WVPASSEQ "$(bup index -s $D/b)" "" WVPASSEQ "$(bup index --check -us $D/b)" "A $D/b" @@ -161,6 +163,14 @@ WVSTART "save/git-fsck" WVPASS [ "$n" -eq 0 ] ) || exit 1 +WVSTART "ftp" +WVPASS bup ftp "cat /master/latest/$TOP/$D/b" >$D/b.new +WVPASS bup ftp "cat /master/latest/$TOP/$D/f" >$D/f.new +WVPASS bup ftp "cat /master/latest/$TOP/$D/a" >$D/a.new +WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)" +WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)" +WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)" + WVSTART "fsck" WVPASS bup fsck WVPASS bup fsck --quick -- 2.39.5