/[rdiff-backup]/rdiff-backup/rdiff_backup/Rdiff.py
ViewVC logotype

Diff of /rdiff-backup/rdiff_backup/Rdiff.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by bescoto, Thu Aug 18 04:12:54 2005 UTC revision 1.13 by bescoto, Thu Oct 27 06:16:39 2005 UTC
# Line 1  Line 1 
1  # Copyright 2002 Ben Escoto  # Copyright 2002 2005 Ben Escoto
2  #  #
3  # This file is part of rdiff-backup.  # This file is part of rdiff-backup.
4  #  #
# Line 20  Line 20 
20  """Invoke rdiff utility to make signatures, deltas, or patch"""  """Invoke rdiff utility to make signatures, deltas, or patch"""
21    
22  import os, librsync  import os, librsync
23  import Globals, log, static, TempFile, rpath  import Globals, log, static, TempFile, rpath, hash
24    
25    
26  def get_signature(rp, blocksize = None):  def get_signature(rp, blocksize = None):
# Line 53  def get_delta_sigrp(rp_signature, rp_new Line 53  def get_delta_sigrp(rp_signature, rp_new
53                          (rp_new.path, rp_signature.get_indexpath()), 7)                          (rp_new.path, rp_signature.get_indexpath()), 7)
54          return librsync.DeltaFile(rp_signature.open("rb"), rp_new.open("rb"))          return librsync.DeltaFile(rp_signature.open("rb"), rp_new.open("rb"))
55    
56    def get_delta_sigrp_hash(rp_signature, rp_new):
57            """Like above but also calculate hash of new as close() value"""
58            log.Log("Getting delta with hash of %s with signature %s" %
59                            (rp_new.path, rp_signature.get_indexpath()), 7)
60            return librsync.DeltaFile(rp_signature.open("rb"),
61                                                              hash.FileWrapper(rp_new.open("rb")))
62            
63    
64  def write_delta(basis, new, delta, compress = None):  def write_delta(basis, new, delta, compress = None):
65          """Write rdiff delta which brings basis to new"""          """Write rdiff delta which brings basis to new"""
66          log.Log("Writing delta %s from %s -> %s" %          log.Log("Writing delta %s from %s -> %s" %
# Line 68  def write_patched_fp(basis_fp, delta_fp, Line 76  def write_patched_fp(basis_fp, delta_fp,
76  def write_via_tempfile(fp, rp):  def write_via_tempfile(fp, rp):
77          """Write fileobj fp to rp by writing to tempfile and renaming"""          """Write fileobj fp to rp by writing to tempfile and renaming"""
78          tf = TempFile.new(rp)          tf = TempFile.new(rp)
79          tf.write_from_fileobj(fp)          retval = tf.write_from_fileobj(fp)
80          rpath.rename(tf, rp)          rpath.rename(tf, rp)
81            return retval
82    
83  def patch_local(rp_basis, rp_delta, outrp = None, delta_compressed = None):  def patch_local(rp_basis, rp_delta, outrp = None, delta_compressed = None):
84          """Patch routine that must be run locally, writes to outrp          """Patch routine that must be run locally, writes to outrp
# Line 83  def patch_local(rp_basis, rp_delta, outr Line 92  def patch_local(rp_basis, rp_delta, outr
92          if delta_compressed: deltafile = rp_delta.open("rb", 1)          if delta_compressed: deltafile = rp_delta.open("rb", 1)
93          else: deltafile = rp_delta.open("rb")          else: deltafile = rp_delta.open("rb")
94          patchfile = librsync.PatchedFile(rp_basis.open("rb"), deltafile)          patchfile = librsync.PatchedFile(rp_basis.open("rb"), deltafile)
95          if outrp: outrp.write_from_fileobj(patchfile)          if outrp: return outrp.write_from_fileobj(patchfile)
96          else: write_via_tempfile(patchfile, rp_basis)          else: return write_via_tempfile(patchfile, rp_basis)
97    
98  def copy_local(rpin, rpout, rpnew = None):  def copy_local(rpin, rpout, rpnew = None):
99          """Write rpnew == rpin using rpout as basis.  rpout and rpnew local"""          """Write rpnew == rpin using rpout as basis.  rpout and rpnew local"""

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26