From: Brandon Low Date: Wed, 12 Jan 2011 01:15:53 +0000 (-0800) Subject: save: handle backup write errors properly X-Git-Tag: bup-0.22~15 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;ds=sidebyside;h=76343e4b2d17d653d5f1dfd1068117aaa53d76d0;p=bup.git save: handle backup write errors properly bup-save was catching all IOErrors and treating them as data-read failures, but some of them could be backup-write errors. Have git.py and client.py raise distinctive errors when pack write raises IOError. Signed-off-by: Brandon Low --- diff --git a/lib/bup/client.py b/lib/bup/client.py index 0bb5219..6354b91 100644 --- a/lib/bup/client.py +++ b/lib/bup/client.py @@ -318,8 +318,11 @@ class PackWriter_Remote(git.PackWriter): sha, struct.pack('!I', crc), data)) - (self._bwcount, self._bwtime) = \ - _raw_write_bwlimit(self.file, outbuf, self._bwcount, self._bwtime) + try: + (self._bwcount, self._bwtime) = _raw_write_bwlimit( + self.file, outbuf, self._bwcount, self._bwtime) + except IOError, e: + raise ClientError, e, sys.exc_info()[2] self.outbytes += len(data) - 20 - 4 # Don't count sha1+crc self.count += 1 diff --git a/lib/bup/git.py b/lib/bup/git.py index b135053..022d347 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -2,7 +2,7 @@ bup repositories are in Git format. This library allows us to interact with the Git data structures. """ -import os, zlib, time, subprocess, struct, stat, re, tempfile, heapq +import os, sys, zlib, time, subprocess, struct, stat, re, tempfile, heapq from bup.helpers import * from bup import _helpers @@ -557,7 +557,10 @@ class PackWriter: # to our hashsplit algorithm.) f.write() does its own buffering, # but that's okay because we'll flush it in _end(). oneblob = ''.join(datalist) - f.write(oneblob) + try: + f.write(oneblob) + except IOError, e: + raise GitError, e, sys.exc_info()[2] nw = len(oneblob) crc = zlib.crc32(oneblob) & 0xffffffff self._update_idx(sha, crc, nw)