Example #1
0
 def _get_one_sig_fp(cls, dest_rp):
     """Return a signature fp of given index, corresponding to reg file"""
     if not dest_rp.isreg():
         log.ErrorLog.write_if_open(
             "UpdateError", dest_rp,
             "File changed from regular file before signature")
         return None
     if (Globals.process_uid != 0 and not dest_rp.readable()
             and dest_rp.isowner()):
         # This branch can happen with root source and non-root
         # destination.  Permissions are changed permanently, which
         # should propagate to the diffs
         dest_rp.chmod(0o400 | dest_rp.getperms())
     try:
         return Rdiff.get_signature(dest_rp)
     except OSError as e:
         if (e.errno == errno.EPERM or e.errno == errno.EACCES):
             try:
                 # Try chmod'ing anyway -- This can work on NFS and AFS
                 # depending on the setup. We keep the if() statement
                 # above for performance reasons.
                 dest_rp.chmod(0o400 | dest_rp.getperms())
                 return Rdiff.get_signature(dest_rp)
             except OSError:
                 log.Log.FatalError(
                     "Could not open file {fi} for reading. Check "
                     "permissions on file.".format(fi=dest_rp))
         else:
             raise
Example #2
0
    def testRdiffDeltaPatchGzip(self):
        """Same as above by try gzipping patches"""
        rplist = [
            self.basis, self.new, self.delta, self.signature, self.output
        ]
        for rp in rplist:
            if rp.lstat():
                rp.delete()

        MakeRandomFile(self.basis.path)
        MakeRandomFile(self.new.path)
        list(map(rpath.RPath.setdata, [self.basis, self.new]))
        assert self.basis.lstat() and self.new.lstat()
        self.signature.write_from_fileobj(Rdiff.get_signature(self.basis))
        assert self.signature.lstat()
        self.delta.write_from_fileobj(
            Rdiff.get_delta_sigrp(self.signature, self.new))
        assert self.delta.lstat()
        os.system(b"gzip %s" % self.delta.path)
        os.system(b"mv %s.gz %s" % (self.delta.path, self.delta.path))
        self.delta.setdata()

        Rdiff.patch_local(self.basis,
                          self.delta,
                          self.output,
                          delta_compressed=1)
        assert rpath.cmp(self.new, self.output)
        list(map(rpath.RPath.delete, rplist))
Example #3
0
    def testRdiffDeltaPatchGzip(self):
        """Same as above by try gzipping patches"""
        rplist = [
            self.basis, self.new, self.delta, self.signature, self.output
        ]
        for rp in rplist:
            if rp.lstat():
                rp.delete()

        MakeRandomFile(self.basis.path)
        MakeRandomFile(self.new.path)
        list(map(rpath.RPath.setdata, [self.basis, self.new]))
        self.assertTrue(self.basis.lstat() and self.new.lstat())
        self.signature.write_from_fileobj(Rdiff.get_signature(self.basis))
        self.assertTrue(self.signature.lstat())
        self.delta.write_from_fileobj(
            Rdiff.get_delta_sigrp_hash(self.signature, self.new))
        self.assertTrue(self.delta.lstat())
        gzip_path = self.delta.path + b".gz"
        if os.name == "nt":
            # simulate gzip using 7z on Windows
            os_system("7z a -tgzip -sdel -bb0 -y %s %s" %
                      (os.fsdecode(gzip_path), os.fsdecode(self.delta.path)))
        else:
            os_system(b"gzip %s" % self.delta.path)
        os.rename(gzip_path, self.delta.path)
        self.delta.setdata()

        Rdiff.patch_local(self.basis,
                          self.delta,
                          self.output,
                          delta_compressed=1)
        self.assertTrue(rpath.cmp(self.new, self.output))
        list(map(rpath.RPath.delete, rplist))
Example #4
0
	def testRdiffSig(self):
		"""Test making rdiff signatures"""
		sig = rpath.RPath(self.lc,
						  "testfiles/various_file_types/regular_file.sig")
		sigfp = sig.open("r")
		rfsig = Rdiff.get_signature(RPath(self.lc, "testfiles/various_file_types/regular_file"), 2048)
		assert rpath.cmpfileobj(sigfp, rfsig)
		sigfp.close()
		rfsig.close()
Example #5
0
 def testRdiffSig(self):
     """Test making rdiff signatures"""
     sig = rpath.RPath(self.lc,
                       "testfiles/various_file_types/regular_file.sig")
     sigfp = sig.open("r")
     rfsig = Rdiff.get_signature(
         RPath(self.lc, "testfiles/various_file_types/regular_file"), 2048)
     assert rpath.cmpfileobj(sigfp, rfsig)
     sigfp.close()
     rfsig.close()
Example #6
0
 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.cmpfileobj(sigfp, rfsig)
     sigfp.close()
     rfsig.close()
Example #7
0
    def testRdiffRename(self):
        """Rdiff replacing original file with patch outfile"""
        rplist = [self.basis, self.new, self.delta, self.signature]
        for rp in rplist:
            if rp.lstat(): rp.delete()

        MakeRandomFile(self.basis.path)
        MakeRandomFile(self.new.path)
        list(map(rpath.RPath.setdata, [self.basis, self.new]))
        assert self.basis.lstat() and self.new.lstat()
        self.signature.write_from_fileobj(Rdiff.get_signature(self.basis))
        assert self.signature.lstat()
        self.delta.write_from_fileobj(
            Rdiff.get_delta_sigrp(self.signature, self.new))
        assert self.delta.lstat()
        Rdiff.patch_local(self.basis, self.delta)
        assert rpath.cmp(self.basis, self.new)
        list(map(rpath.RPath.delete, rplist))
Example #8
0
	def testRdiffRename(self):
		"""Rdiff replacing original file with patch outfile"""
		rplist = [self.basis, self.new, self.delta, self.signature]
		for rp in rplist:
			if rp.lstat(): rp.delete()

		MakeRandomFile(self.basis.path)
		MakeRandomFile(self.new.path)
		map(rpath.RPath.setdata, [self.basis, self.new])
		assert self.basis.lstat() and self.new.lstat()
		self.signature.write_from_fileobj(Rdiff.get_signature(self.basis))
		assert self.signature.lstat()
		self.delta.write_from_fileobj(Rdiff.get_delta_sigrp(self.signature,
															self.new))
		assert self.delta.lstat()
		Rdiff.patch_local(self.basis, self.delta)
		assert rpath.cmp(self.basis, self.new)
		map(rpath.RPath.delete, rplist)
Example #9
0
	def testRdiffDeltaPatch(self):
		"""Test making deltas and patching files"""
		rplist = [self.basis, self.new, self.delta,
				  self.signature, self.output]
		for rp in rplist:
			if rp.lstat(): rp.delete()
			
		for i in range(2):
			MakeRandomFile(self.basis.path)
			MakeRandomFile(self.new.path)
			map(rpath.RPath.setdata, [self.basis, self.new])
			assert self.basis.lstat() and self.new.lstat()
			self.signature.write_from_fileobj(Rdiff.get_signature(self.basis))
			assert self.signature.lstat()
			self.delta.write_from_fileobj(Rdiff.get_delta_sigrp(self.signature,
																self.new))
			assert self.delta.lstat()
			Rdiff.patch_local(self.basis, self.delta, self.output)
			assert rpath.cmp(self.new, self.output)
			map(rpath.RPath.delete, rplist)
Example #10
0
    def testRdiffDeltaPatch(self):
        """Test making deltas and patching files"""
        rplist = [
            self.basis, self.new, self.delta, self.signature, self.output
        ]
        for rp in rplist:
            if rp.lstat(): rp.delete()

        for i in range(2):
            MakeRandomFile(self.basis.path)
            MakeRandomFile(self.new.path)
            list(map(rpath.RPath.setdata, [self.basis, self.new]))
            assert self.basis.lstat() and self.new.lstat()
            self.signature.write_from_fileobj(Rdiff.get_signature(self.basis))
            assert self.signature.lstat()
            self.delta.write_from_fileobj(
                Rdiff.get_delta_sigrp(self.signature, self.new))
            assert self.delta.lstat()
            Rdiff.patch_local(self.basis, self.delta, self.output)
            assert rpath.cmp(self.new, self.output)
            list(map(rpath.RPath.delete, rplist))
Example #11
0
	def testRdiffDeltaPatchGzip(self):
		"""Same as above by try gzipping patches"""
		rplist = [self.basis, self.new, self.delta,
				  self.signature, self.output]
		for rp in rplist:
			if rp.lstat(): rp.delete()
			
		MakeRandomFile(self.basis.path)
		MakeRandomFile(self.new.path)
		map(rpath.RPath.setdata, [self.basis, self.new])
		assert self.basis.lstat() and self.new.lstat()
		self.signature.write_from_fileobj(Rdiff.get_signature(self.basis))
		assert self.signature.lstat()
		self.delta.write_from_fileobj(Rdiff.get_delta_sigrp(self.signature,
															self.new))
		assert self.delta.lstat()
		os.system("gzip " + self.delta.path)
		os.system("mv %s %s" % (self.delta.path + ".gz", self.delta.path))
		self.delta.setdata()

		Rdiff.patch_local(self.basis, self.delta, self.output,
						  delta_compressed = 1)
		assert rpath.cmp(self.new, self.output)
		map(rpath.RPath.delete, rplist)