Index: rpath.py =================================================================== RCS file: /sources/rdiff-backup/rdiff-backup/rdiff_backup/rpath.py,v retrieving revision 1.142 diff -u -r1.142 rpath.py --- rpath.py 23 Jun 2009 23:56:30 -0000 1.142 +++ rpath.py 3 Jan 2011 03:27:04 -0000 @@ -58,10 +58,44 @@ def copyfileobj(inputfp, outputfp): """Copies file inputfp to outputfp in blocksize intervals""" blocksize = Globals.blocksize + + sparse = False + buf = None while 1: inbuf = inputfp.read(blocksize) if not inbuf: break - outputfp.write(inbuf) + + if not buf: + buf = inbuf + else: + buf += inbuf + + # Combine "short" reads + if (len(buf) < blocksize): + continue + + buflen = len(buf) + if buf == "\x00" * buflen: + outputfp.seek(buflen, os.SEEK_CUR) + buf = None + # flag sparse=True, that we seek()ed, but have not written yet + # The filesize is wrong until we write + sparse = True + else: + outputfp.write(buf) + buf = None + + # We wrote, so clear sparse. + sparse = False + + + if buf: + outputfp.write(buf) + buf = None + + elif sparse: + outputfp.seek(-1, os.SEEK_CUR) + outputfp.write("\x00") def cmpfileobj(fp1, fp2): """True if file objects fp1 and fp2 contain same data"""