コード例 #1
0
ファイル: backup.py プロジェクト: dylex/rdiff-backup
	def fast_process(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 = TempFile.new(mirror_rp)
		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)
				elif inc.renamed:
					self.CCPP.flag_deleted(index)
				return # normal return, otherwise error occurred
		tf.setdata()
		if tf.lstat(): tf.delete()
コード例 #2
0
 def fast_process(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 = TempFile.new(mirror_rp)
     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()
コード例 #3
0
ファイル: backup.py プロジェクト: amon-ra/rdiff-backup
	def set_dir_replacement(self, diff_rorp, base_rp):
		"""Set self.dir_replacement, which holds data until done with dir

		This is used when base_rp is a dir, and diff_rorp is not.
		Returns 1 for success or 0 for failure

		"""
		assert diff_rorp.get_attached_filetype() == 'snapshot'
		self.dir_replacement = TempFile.new(base_rp)
		if not self.patch_to_temp(None, diff_rorp, self.dir_replacement):
			if self.dir_replacement.lstat(): self.dir_replacement.delete()
			# Was an error, so now restore original directory
			rpath.copy_with_attribs(self.CCPP.get_mirror_rorp(diff_rorp.index),
									self.dir_replacement)
			return 0
		else: return 1
コード例 #4
0
ファイル: backup.py プロジェクト: amon-ra/rdiff-backup
	def fast_process(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_rp
		tf = TempFile.new(mirror_rp)
		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()
コード例 #5
0
ファイル: regress.py プロジェクト: Christoph-D/rdiff-backup
	def restore_orig_regfile(self, rf):
		"""Restore original regular file

		This is the trickiest case for avoiding information loss,
		because we don't want to delete the increment before the
		mirror is fully written.

		"""
		assert rf.metadata_rorp.isreg()
		if rf.mirror_rp.isreg():
			tf = TempFile.new(rf.mirror_rp)
			tf.write_from_fileobj(rf.get_restore_fp())
			tf.fsync_with_dir() # make sure tf fully written before move
			rpath.copy_attribs(rf.metadata_rorp, tf)
			rpath.rename(tf, rf.mirror_rp) # move is atomic
		else:
			if rf.mirror_rp.lstat(): rf.mirror_rp.delete()
			rf.mirror_rp.write_from_fileobj(rf.get_restore_fp())
			rpath.copy_attribs(rf.metadata_rorp, rf.mirror_rp)
		if Globals.fsync_directories:
			rf.mirror_rp.get_parent_rp().fsync() # force move before inc delete
コード例 #6
0
ファイル: regress.py プロジェクト: tnt/rdiff-backup
    def restore_orig_regfile(self, rf):
        """Restore original regular file

		This is the trickiest case for avoiding information loss,
		because we don't want to delete the increment before the
		mirror is fully written.

		"""
        assert rf.metadata_rorp.isreg()
        if rf.mirror_rp.isreg():
            tf = TempFile.new(rf.mirror_rp)
            tf.write_from_fileobj(rf.get_restore_fp())
            tf.fsync_with_dir()  # make sure tf fully written before move
            rpath.copy_attribs(rf.metadata_rorp, tf)
            rpath.rename(tf, rf.mirror_rp)  # move is atomic
        else:
            if rf.mirror_rp.lstat(): rf.mirror_rp.delete()
            rf.mirror_rp.write_from_fileobj(rf.get_restore_fp())
            rpath.copy_attribs(rf.metadata_rorp, rf.mirror_rp)
        if Globals.fsync_directories:
            rf.mirror_rp.get_parent_rp().fsync(
            )  # force move before inc delete
コード例 #7
0
def write_via_tempfile(fp, rp):
	"""Write fileobj fp to rp by writing to tempfile and renaming"""
	tf = TempFile.new(rp)
	retval = tf.write_from_fileobj(fp)
	rpath.rename(tf, rp)
	return retval