Commit 6d517327 authored by Guillaume Hervier's avatar Guillaume Hervier

Implement lazy file opening for diff generation

parent 76799c30
class LazyFile:
def __init__(self, path, *args, **kwargs):
self.path = path
self.args = args
self.kwargs = kwargs
self.file = None
def read(self, length=-1):
self.open()
return self.file.read(length)
def open(self):
if self.file is None:
self.file = open(self.path, *self.args, **self.kwargs)
def close(self):
if self.file is None:
return None
value = self.file.close()
self.file = None
return value
def lazy_open(path, *args, **kwargs):
return LazyFile(path, *args, **kwargs)
......@@ -24,6 +24,7 @@ from __future__ import generators
from pool import Pool as ThreadPool
import tempfile, os, cStringIO, itertools
import static, rorpiter, FilenameMapping, connection
import opener
class RestoreError(Exception): pass
......@@ -294,7 +295,8 @@ class MirrorStruct:
# a file is already there, we can create a diff
signature_vf = target_rorp.conn.Rdiff.get_signature_vf(target_rorp)
target_signature = connection.VirtualFile(target_rorp.conn, signature_vf)
delta_fp = mir_rorp.get_delta(target_signature, open(file_fp.name, 'rb'))
file_fobj = opener.lazy_open(file_fp.name, 'rb')
delta_fp = mir_rorp.get_delta(target_signature, file_fobj)
mir_rorp.setfile(delta_fp)
else:
# standard rdiff-backup behavior, transfer everything
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment