Skip to content

Commit

Permalink
vfs: correctly handle reading small files.
Browse files Browse the repository at this point in the history
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 <apenwarr@gmail.com>
  • Loading branch information
apenwarr committed Jun 25, 2010
1 parent 73a84ee commit a63f1c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cmd/ftp-cmd.py
Expand Up @@ -125,6 +125,7 @@ def completer(text, state):

top = vfs.RefList(None)
pwd = top
rv = 0

if extra:
lines = extra
Expand Down Expand Up @@ -156,6 +157,7 @@ def completer(text, state):
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 <filename> [localname]')
rname = words[1]
(dir,base) = os.path.split(rname)
Expand All @@ -175,13 +177,18 @@ def completer(text, state):
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)
2 changes: 1 addition & 1 deletion lib/bup/vfs.py
Expand Up @@ -88,7 +88,7 @@ def __init__(self, hash, isdir, startofs):
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 = ''
Expand Down
12 changes: 11 additions & 1 deletion t/test.sh
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a63f1c9

Please sign in to comment.