def _compare_at_time(self, t): """Restore file, make sure it is the same at time t""" log.Log("Checking result at time %s" % (t, ), 7) tf = tempdir.get_temp_rpath() restore.MirrorStruct._mirror_time = mirror_time restore.MirrorStruct._rest_time = t self.rf.set_relevant_incs() out_rorpath = self.rf.get_attribs().getRORPath() correct_result = self.time_rp_dict[t] if out_rorpath.isreg(): out_rorpath.setfile(self.rf.get_restore_fp()) rpath.copy_with_attribs(out_rorpath, tf) if not tf._equal_verbose(correct_result, check_index=0): return ("Restored file {rest!s} isn't same " "as original file {orig!s}.".format(rest=tf, orig=correct_result)) if tf.isreg(): with tf.open("rb") as tf_fd, correct_result.open("rb") as corr_fd: if not rpath._cmp_file_obj(tf_fd, corr_fd): return ("Content of restored file {rest!s} isn't same " "as original file {orig!s}.".format( rest=tf, orig=correct_result)) if tf.lstat(): tf.delete() return () # no error found
def testVirtualFiles(self): """Testing virtual files""" # generate file name for temporary file temp_file = os.path.join(abs_test_dir, b"tempout") tempout = self.conn.open(temp_file, "wb") assert isinstance(tempout, VirtualFile) regfilefp = open(regfilename, "rb") rpath.copyfileobj(regfilefp, tempout) tempout.close() regfilefp.close() tempoutlocal = open(temp_file, "rb") regfilefp = open(regfilename, "rb") assert rpath._cmp_file_obj(regfilefp, tempoutlocal) tempoutlocal.close() regfilefp.close() os.unlink(temp_file) with open(regfilename, "rb") as localfh: assert rpath._cmp_file_obj(self.conn.open(regfilename, "rb"), localfh)
def testGzipsnapshot(self): """Test making a compressed snapshot""" Globals.compression = 1 rp = increment.Increment(rf, sym, target) self.check_time(rp) assert rp._equal_verbose(sym, check_index=0, compare_size=0) assert rpath.cmp(rp, sym) rp.delete() rp = increment.Increment(sym, rf, target) self.check_time(rp) assert rp._equal_verbose(rf, check_index=0, compare_size=0) assert rpath._cmp_file_obj(rp.open("rb", 1), rf.open("rb")) assert rp.isinccompressed() rp.delete()
def testRdiffSig(self): """Test making rdiff signatures""" sig = rpath.RPath( self.lc, os.path.join(old_test_dir, b"various_file_types", b"regular_file.sig")) sigfp = sig.open("rb") rfsig = Rdiff.get_signature( rpath.RPath( self.lc, os.path.join(old_test_dir, b"various_file_types", b"regular_file")), 2048) assert rpath._cmp_file_obj(sigfp, rfsig) sigfp.close() rfsig.close()
def compare_at_time(self, t): """Restore file, make sure it is the same at time t""" log.Log("Checking result at time %s" % (t, ), 7) tf = tempdir.get_temp_rpath() restore.MirrorStruct._mirror_time = mirror_time restore.MirrorStruct._rest_time = t self.rf.set_relevant_incs() out_rorpath = self.rf.get_attribs().getRORPath() correct_result = self.time_rp_dict[t] if out_rorpath.isreg(): out_rorpath.setfile(self.rf.get_restore_fp()) rpath.copy_with_attribs(out_rorpath, tf) assert tf._equal_verbose(correct_result, check_index=0), \ "%s, %s" % (tf, correct_result) if tf.isreg(): with tf.open("rb") as tf_fd, correct_result.open("rb") as corr_fd: assert rpath._cmp_file_obj(tf_fd, corr_fd) if tf.lstat(): tf.delete()