コード例 #1
0
ファイル: backup.py プロジェクト: rdiff-backup/rdiff-backup
 def fast_process_file(self, index, diff_rorp):
     """Patch base_rp with diff_rorp and write increment (neither is dir)"""
     mirror_rp, inc_prefix = longname.get_mirror_inc_rps(
         self.CCPP.get_rorps(index), self.basis_root_rp, self.inc_root_rp)
     tf = mirror_rp.get_temp_rpath(sibling=True)
     if self._patch_to_temp(mirror_rp, diff_rorp, tf):
         inc = robust.check_common_error(self.error_handler,
                                         increment.Increment,
                                         (tf, mirror_rp, inc_prefix))
         if inc is not None and not isinstance(inc, int):
             self.CCPP.set_inc(index, inc)
             if inc.isreg():
                 inc.fsync_with_dir()  # Write inc before rp changed
             if tf.lstat():
                 if robust.check_common_error(self.error_handler,
                                              rpath.rename,
                                              (tf, mirror_rp)) is None:
                     self.CCPP.flag_success(index)
                 else:
                     tf.delete()
             elif mirror_rp.lstat():
                 mirror_rp.delete()
                 self.CCPP.flag_deleted(index)
             return  # normal return, otherwise error occurred
     tf.setdata()
     if tf.lstat():
         tf.delete()
コード例 #2
0
	def test_check_common_error(self):
		"""Test capturing errors"""
		def cause_catchable_error(a):
			os.lstat("aoenuthaoeu/aosutnhcg.4fpr,38p")
		def cause_uncatchable_error():
			ansoethusaotneuhsaotneuhsaontehuaou
		result = robust.check_common_error(None, cause_catchable_error, [1])
		assert result is None, result
		try: robust.check_common_error(None, cause_uncatchable_error)
		except NameError: pass
		else: assert 0, "Key error not raised"
コード例 #3
0
ファイル: robusttest.py プロジェクト: user-na/rdiff-backup
    def test_check_common_error(self):
        """Test capturing errors"""
        def cause_catchable_error(a):
            os.lstat("aoenuthaoeu/aosutnhcg.4fpr,38p")

        def cause_uncatchable_error():
            ansoethusaotneuhsaotneuhsaontehuaou  # noqa: F821 undefined name

        result = robust.check_common_error(None, cause_catchable_error, [1])
        self.assertIsNone(result)
        with self.assertRaises(NameError):
            robust.check_common_error(None, cause_uncatchable_error)
コード例 #4
0
ファイル: backup.py プロジェクト: rdiff-backup/rdiff-backup
 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()
コード例 #5
0
ファイル: robusttest.py プロジェクト: lazyfrosch/rdiff-backup
    def test_check_common_error(self):
        """Test capturing errors"""

        def cause_catchable_error(a):
            os.lstat("aoenuthaoeu/aosutnhcg.4fpr,38p")

        def cause_uncatchable_error():
            ansoethusaotneuhsaotneuhsaontehuaou

        result = robust.check_common_error(None, cause_catchable_error, [1])
        assert result is None, result
        try:
            robust.check_common_error(None, cause_uncatchable_error)
        except NameError:
            pass
        else:
            assert 0, "Key error not raised"
コード例 #6
0
ファイル: backup.py プロジェクト: rdiff-backup/rdiff-backup
 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')
コード例 #7
0
ファイル: backup.py プロジェクト: rdiff-backup/rdiff-backup
 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')
コード例 #8
0
ファイル: regress.py プロジェクト: rdiff-backup/rdiff-backup
 def fast_process_file(self, index, rf):
     """Process when nothing is a directory"""
     if not rf.metadata_rorp.equal_loose(rf.mirror_rp):
         log.Log("Regressing file {fi}".format(fi=rf.metadata_rorp),
                 log.INFO)
         if rf.metadata_rorp.isreg():
             self._restore_orig_regfile(rf)
         else:
             if rf.mirror_rp.lstat():
                 rf.mirror_rp.delete()
             if rf.metadata_rorp.isspecial():
                 robust.check_common_error(None, rpath.copy_with_attribs,
                                           (rf.metadata_rorp, rf.mirror_rp))
             else:
                 rpath.copy_with_attribs(rf.metadata_rorp, rf.mirror_rp)
     if rf.regress_inc:
         log.Log("Deleting increment {ic}".format(ic=rf.regress_inc),
                 log.INFO)
         rf.regress_inc.delete()
コード例 #9
0
ファイル: backup.py プロジェクト: rdiff-backup/rdiff-backup
 def _patch_diff_to_temp(self, basis_rp, diff_rorp, new):
     """Apply diff_rorp to basis_rp, write output in new"""
     assert diff_rorp.get_attached_filetype() == 'diff', (
         "Type attached to '{rp}' isn't '{exp}' but '{att}'.".format(
             rp=diff_rorp, exp="diff",
             att=diff_rorp.get_attached_filetype()))
     report = robust.check_common_error(
         self.error_handler, Rdiff.patch_local, (basis_rp, diff_rorp, new))
     if isinstance(report, hash.Report):
         self.CCPP.update_hash(diff_rorp.index, report.sha1_digest)
         return 1
     return report != 0  # if report == 0, error
コード例 #10
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
コード例 #11
0
ファイル: backup.py プロジェクト: rdiff-backup/rdiff-backup
    def _patch_snapshot_to_temp(self, diff_rorp, new):
        """Write diff_rorp to new, return true if successful

        Returns 1 if normal success, 2 if special file is written,
        whether or not it is successful.  This is because special
        files either fail with a SpecialFileError, or don't need to be
        compared.

        """
        if diff_rorp.isspecial():
            self._write_special(diff_rorp, new)
            rpath.copy_attribs(diff_rorp, new)
            return 2

        report = robust.check_common_error(self.error_handler, rpath.copy,
                                           (diff_rorp, new))
        if isinstance(report, hash.Report):
            self.CCPP.update_hash(diff_rorp.index, report.sha1_digest)
            return 1
        return report != 0  # if == 0, error_handler caught something
コード例 #12
0
ファイル: backup.py プロジェクト: rdiff-backup/rdiff-backup
 def fast_process_file(self, index, diff_rorp):
     """Patch base_rp with diff_rorp (case where neither is directory)"""
     mirror_rp, discard = longname.get_mirror_inc_rps(
         self.CCPP.get_rorps(index), self.basis_root_rp)
     assert not mirror_rp.isdir(), (
         "Mirror path '{rp}' points to a directory.".format(rp=mirror_rp))
     tf = mirror_rp.get_temp_rpath(sibling=True)
     if self._patch_to_temp(mirror_rp, diff_rorp, tf):
         if tf.lstat():
             if robust.check_common_error(self.error_handler, rpath.rename,
                                          (tf, mirror_rp)) is None:
                 self.CCPP.flag_success(index)
             else:
                 tf.delete()
         elif mirror_rp and mirror_rp.lstat():
             mirror_rp.delete()
             self.CCPP.flag_deleted(index)
     else:
         tf.setdata()
         if tf.lstat():
             tf.delete()
コード例 #13
0
 def data_changed(src_rp, repo_rorp):
     """Return 0 if full compare of data matches, 1 otherwise"""
     if src_rp.getsize() != repo_rorp.getsize():
         return 1
     return not robust.check_common_error(error_handler, rpath.cmp,
                                          (src_rp, repo_rorp))