Ejemplo n.º 1
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)
				elif inc.renamed:
					self.CCPP.flag_deleted(index)
				return # normal return, otherwise error occurred
		tf.setdata()
		if tf.lstat(): tf.delete()
Ejemplo n.º 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()
Ejemplo n.º 3
0
	def fast_process(self, index, rf):
		"""Process when nothing is a directory"""
		if not rf.metadata_rorp.equal_loose(rf.mirror_rp):
			log.Log("Regressing file %s" %
					(rf.metadata_rorp.get_indexpath()), 5)
			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 " + rf.regress_inc.path, 5)
			rf.regress_inc.delete()
Ejemplo n.º 4
0
		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')
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
 def fast_process(self, index, rf):
     """Process when nothing is a directory"""
     if not rf.metadata_rorp.equal_loose(rf.mirror_rp):
         log.Log("Regressing file %s" % (rf.metadata_rorp.get_indexpath()),
                 5)
         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 " + rf.regress_inc.path, 5)
         rf.regress_inc.delete()
Ejemplo n.º 7
0
	def listdir(self, dir_rp):
		"""List directory rpath with error logging"""
		def error_handler(exc):
			log.ErrorLog.write_if_open("ListError", dir_rp, exc)
			return []
		dir_listing = robust.check_common_error(error_handler, dir_rp.listdir)
		dir_listing.sort()
		return dir_listing
Ejemplo n.º 8
0
	def listdir(self, dir_rp):
		"""List directory rpath with error logging"""
		def error_handler(exc):
			log.ErrorLog.write_if_open("ListError", dir_rp, exc)
			return []
		dir_listing = robust.check_common_error(error_handler, dir_rp.listdir)
		dir_listing.sort()
		return dir_listing
Ejemplo n.º 9
0
	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'
		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
Ejemplo n.º 10
0
		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')
Ejemplo n.º 11
0
    def iterate_in_dir(self, rpath, rec_func, sel_func):
        """Iterate the rpaths in directory rpath."""
        def error_handler(exc, filename):
            log.ErrorLog.write_if_open("ListError", rpath.index + (filename, ),
                                       exc)
            return None

        for filename in self.listdir(rpath):
            new_rp = robust.check_common_error(error_handler, rpath.append,
                                               [filename])
            if new_rp:
                for rp in rec_func(new_rp, rec_func, sel_func):
                    yield rp
Ejemplo n.º 12
0
	def iterate_in_dir(self, rpath, rec_func, sel_func):
		"""Iterate the rpaths in directory rpath."""
		def error_handler(exc, filename):
			log.ErrorLog.write_if_open("ListError",
									   rpath.index + (filename,), exc)
			return None

		for filename in self.listdir(rpath):
			new_rp = robust.check_common_error(
				error_handler, rpath.append, [filename])
			if new_rp:
				for rp in rec_func(new_rp, rec_func, sel_func):
					yield rp
Ejemplo n.º 13
0
		def diryield(rpath):
			"""Generate relevant files in directory rpath

			Returns (rpath, num) where num == 0 means rpath should be
			generated normally, num == 1 means the rpath is a directory
			and should be included iff something inside is included.

			"""
			for filename in self.listdir(rpath):
				new_rpath = robust.check_common_error(error_handler,
										rpath.append, (filename,))
				if new_rpath and new_rpath.lstat():
					s = sel_func(new_rpath)
					if s == 1: yield (new_rpath, 0)
					elif s == 2 and new_rpath.isdir(): yield (new_rpath, 1)
Ejemplo n.º 14
0
		def diryield(rpath):
			"""Generate relevant files in directory rpath

			Returns (rpath, num) where num == 0 means rpath should be
			generated normally, num == 1 means the rpath is a directory
			and should be included iff something inside is included.

			"""
			for filename in self.listdir(rpath):
				new_rpath = robust.check_common_error(error_handler,
										rpath.append, (filename,))
				if new_rpath and new_rpath.lstat():
					s = sel_func(new_rpath)
					if s == 1: yield (new_rpath, 0)
					elif s == 2 and new_rpath.isdir(): yield (new_rpath, 1)
Ejemplo n.º 15
0
def makesnapshot(mirror, incpref):
	"""Copy mirror to incfile, since new is quite different"""
	compress = iscompressed(mirror)
	if compress and mirror.isreg():
		snapshotrp = get_inc(incpref, "snapshot.gz")
	else: snapshotrp = get_inc(incpref, "snapshot")

	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
Ejemplo n.º 16
0
	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()
Ejemplo n.º 17
0
	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
Ejemplo n.º 18
0
	def addfromfile(self, prefix_letter):
		"""Read a chunk from the current file and add to array_buf

		prefix_letter and the length will be prepended to the file
		data.  If there is an exception while reading the file, the
		exception will be added to array_buf instead.

		"""
		buf = robust.check_common_error(self.read_error_handler,
										self.currently_in_file.read,
										[Globals.blocksize])
		if buf is None: # error occurred above, encode exception
			self.currently_in_file = None
			excstr = cPickle.dumps(self.last_exception, 1)
			total = "".join(('e', C.long2str(long(len(excstr))), excstr))
		else:
			total = "".join((prefix_letter, C.long2str(long(len(buf))), buf))
			if buf == "": # end of file
				cstr = cPickle.dumps(self.currently_in_file.close(), 1)
				self.currently_in_file = None
				total += "".join(('h', C.long2str(long(len(cstr))), cstr))
		self.array_buf.fromstring(total)
Ejemplo n.º 19
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))
Ejemplo n.º 20
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))