]> arthur.barton.de Git - bup.git/commitdiff
vfs: correctly handle reading small files.
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 25 Jun 2010 17:13:49 +0000 (13:13 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 25 Jun 2010 17:15:29 +0000 (13:15 -0400)
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>
cmd/ftp-cmd.py
lib/bup/vfs.py
t/test.sh

index 7c2823fa1f7f214a6bf04324d9ac50500fc686d0..c6f26af7700eb1eab8be62317416cb09fbcc8913 100755 (executable)
@@ -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 <filename> [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)
index c8f688a9c33f096311dabbcbda1bee2a595328ec..ea33818647398c9c247800f71e0ca166ea291376 100644 (file)
@@ -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 = ''
index 007f74512d39908eef6fd97faca17c84a9a1548e..63982362b62eb4bb33d2e8ba18ddf09418a3a3f3 100755 (executable)
--- 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