예제 #1
0
 def _write_special(self, diff_rorp, new):
     """Write diff_rorp (which holds special file) to new"""
     eh = robust.get_error_handler("SpecialFileError")
     if robust.check_common_error(eh, rpath.copy, (diff_rorp, new)) == 0:
         new.setdata()
         if new.lstat():
             new.delete()
         new.touch()
예제 #2
0
    def get_diffs(cls, dest_sigiter):
        """
        Return diffs of any files with signature in dest_sigiter
        """
        source_rps = cls._select
        error_handler = robust.get_error_handler("ListError")

        def attach_snapshot(diff_rorp, src_rp):
            """Attach file of snapshot to diff_rorp, w/ error checking"""
            fileobj = robust.check_common_error(error_handler,
                                                rpath.RPath.open,
                                                (src_rp, "rb"))
            if fileobj:
                diff_rorp.setfile(hash.FileWrapper(fileobj))
            else:
                diff_rorp.zero()
            diff_rorp.set_attached_filetype('snapshot')

        def attach_diff(diff_rorp, src_rp, dest_sig):
            """Attach file of diff to diff_rorp, w/ error checking"""
            fileobj = robust.check_common_error(error_handler,
                                                Rdiff.get_delta_sigrp_hash,
                                                (dest_sig, src_rp))
            if fileobj:
                diff_rorp.setfile(fileobj)
                diff_rorp.set_attached_filetype('diff')
            else:
                diff_rorp.zero()
                diff_rorp.set_attached_filetype('snapshot')

        for dest_sig in dest_sigiter:
            if dest_sig is iterfile.MiscIterFlushRepeat:
                yield iterfile.MiscIterFlush  # Flush buffer when get_sigs does
                continue
            src_rp = (source_rps.get(dest_sig.index)
                      or rpath.RORPath(dest_sig.index))
            diff_rorp = src_rp.getRORPath()
            if dest_sig.isflaglinked():
                diff_rorp.flaglinked(dest_sig.get_link_flag())
            elif src_rp.isreg():
                reset_perms = False
                if (Globals.process_uid != 0 and not src_rp.readable()
                        and src_rp.isowner()):
                    reset_perms = True
                    src_rp.chmod(0o400 | src_rp.getperms())

                if dest_sig.isreg():
                    attach_diff(diff_rorp, src_rp, dest_sig)
                else:
                    attach_snapshot(diff_rorp, src_rp)

                if reset_perms:
                    src_rp.chmod(src_rp.getperms() & ~0o400)
            else:
                dest_sig.close_if_necessary()
                diff_rorp.set_attached_filetype('snapshot')
            yield diff_rorp
예제 #3
0
 def __init__(self, basis_root_rp, CCPP):
     """Set basis_root_rp, the base of the tree to be incremented"""
     self.basis_root_rp = basis_root_rp
     assert basis_root_rp.conn is Globals.local_connection, (
         "Basis root path connection {conn} isn't "
         "local connection {lconn}.".format(
             conn=basis_root_rp.conn, lconn=Globals.local_connection))
     self.statfileobj = (statistics.get_active_statfileobj()
                         or statistics.StatFileObj())
     self.dir_replacement, self.dir_update = None, None
     self.CCPP = CCPP
     self.error_handler = robust.get_error_handler("UpdateError")
예제 #4
0
def _make_snapshot_increment(mirror, incpref, inc_time):
    """Copy mirror to incfile, since new is quite different"""
    compress = _is_compressed(mirror)
    if compress and mirror.isreg():
        snapshotrp = get_inc(incpref, b"snapshot.gz", inc_time)
    else:
        snapshotrp = get_inc(incpref, b"snapshot", inc_time)

    if mirror.isspecial():  # check for errors when creating special increments
        eh = robust.get_error_handler("SpecialFileError")
        if robust.check_common_error(eh, rpath.copy_with_attribs,
                                     (mirror, snapshotrp, compress)) == 0:
            snapshotrp.setdata()
            if snapshotrp.lstat():
                snapshotrp.delete()
            snapshotrp.touch()
    else:
        rpath.copy_with_attribs(mirror, snapshotrp, compress)
    return snapshotrp