Example #1
0
    def _check_one_archive(self, obj, path, archpath, verbose=False):
        is_ok = True

        # Calculate checksums
        arch_chksum = compute_file_checksums(archpath, obj.checksum_type)[obj.checksum_type]
        chksum = compute_file_checksums(path, obj.open_checksum_type)[obj.open_checksum_type]
        if arch_chksum != obj.checksum:
            self.vprint("repomd.xml: Archive checksum doesn't match: %s" % archpath, verbose)
            is_ok = False
        if chksum != obj.open_checksum:
            self.vprint("repomd.xml: Open checksum doesn't match: %s" % path, verbose)
            is_ok = False

        # Check stat
        archpath_st = os.stat(archpath)
        path_st = os.stat(path)

        if archpath_st.st_size != int(obj.size):
            self.vprint("repomd.xml: Archive size doesn't match: %s" % archpath, verbose)
        if path_st.st_size != int(obj.open_size):
            self.vprint("repomd.xml: Open size doesn't match: %s" % archpath, verbose)

        # Conversion to int => Ignore numbers after decimal point
        if int(archpath_st.st_mtime) != int(float(obj.timestamp)):
            self.vprint("repomd.xml: Mtime doesn't match: %s" % archpath, verbose)

        return is_ok
Example #2
0
 def test_compute_file_checksums(self):
     self.assertEqual(compute_file_checksums(self.tmp_file, "md5"),
                      dict(md5="098f6bcd4621d373cade4e832627b4f6"))
     self.assertEqual(
         compute_file_checksums(self.tmp_file, ["md5", "sha256"]),
         dict(
             md5="098f6bcd4621d373cade4e832627b4f6",
             sha256=
             "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
         ))
     self.assertEqual(compute_file_checksums(self.tmp_file, ["md5", "md5"]),
                      dict(md5="098f6bcd4621d373cade4e832627b4f6"))
     self.assertRaises(ValueError, compute_file_checksums, self.tmp_file,
                       "unsupported_checksum")
Example #3
0
    def _check_one_archive(self, obj, path, archpath, verbose=False):
        is_ok = True

        # Calculate checksums
        arch_chksum = compute_file_checksums(
            archpath, obj.checksum_type)[obj.checksum_type]
        chksum = compute_file_checksums(
            path, obj.open_checksum_type)[obj.open_checksum_type]
        if arch_chksum != obj.checksum:
            self.vprint(
                "repomd.xml: Archive checksum doesn't match: %s" % archpath,
                verbose)
            is_ok = False
        if chksum != obj.open_checksum:
            self.vprint("repomd.xml: Open checksum doesn't match: %s" % path,
                        verbose)
            is_ok = False

        # Check stat
        archpath_st = os.stat(archpath)
        path_st = os.stat(path)

        if archpath_st.st_size != int(obj.size):
            self.vprint(
                "repomd.xml: Archive size doesn't match: %s" % archpath,
                verbose)
        if path_st.st_size != int(obj.open_size):
            self.vprint("repomd.xml: Open size doesn't match: %s" % archpath,
                        verbose)

        # Conversion to int => Ignore numbers after decimal point
        if int(archpath_st.st_mtime) != int(float(obj.timestamp)):
            self.vprint("repomd.xml: Mtime doesn't match: %s" % archpath,
                        verbose)

        return is_ok
Example #4
0
    def compute_checksums(self, checksum_types):
        """Compute and cache checksums of given types."""

        result = {}
        missing = []
        checksum_types = force_list(checksum_types)

        for checksum_type in checksum_types:
            if checksum_type in self._checksums:
                result[checksum_type] = self._checksums[checksum_type]
            else:
                missing.append(checksum_type)

        if missing:
            result.update(compute_file_checksums(self.file_path, missing))
            self._checksums.update(result)

        return result
Example #5
0
    def compute_checksums(self, checksum_types):
        """Compute and cache checksums of given types."""

        result = {}
        missing = []
        checksum_types = force_list(checksum_types)

        for checksum_type in checksum_types:
            if checksum_type in self._checksums:
                result[checksum_type] = self._checksums[checksum_type]
            else:
                missing.append(checksum_type)

        if missing:
            result.update(compute_file_checksums(self.file_path, missing))
            self._checksums.update(result)

        return result
Example #6
0
 def test_compute_file_checksums(self):
     self.assertEqual(compute_file_checksums(self.tmp_file, "md5"), dict(md5="098f6bcd4621d373cade4e832627b4f6"))
     self.assertEqual(compute_file_checksums(self.tmp_file, ["md5", "sha256"]), dict(md5="098f6bcd4621d373cade4e832627b4f6", sha256="9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"))
     self.assertEqual(compute_file_checksums(self.tmp_file, ["md5", "md5"]), dict(md5="098f6bcd4621d373cade4e832627b4f6"))
     self.assertRaises(ValueError, compute_file_checksums, self.tmp_file, "unsupported_checksum")