Skip to content
Tomas Mlcoch edited this page Oct 20, 2015 · 1 revision

Implementation of --cachedir in original createrepo

yumbased.py / CreateRepoPackage()._do_checksum

Algorithm

If the --cachedir is not used, a checksum of a package is classically calculated and returned.

If the --cachedir is used then:

Key for the package is calculated like a:

t = []
if type(self.hdr[rpm.RPMTAG_SIGGPG]) is not types.NoneType:
    t.append("".join(self.hdr[rpm.RPMTAG_SIGGPG]))
if type(self.hdr[rpm.RPMTAG_SIGPGP]) is not types.NoneType:
    t.append("".join(self.hdr[rpm.RPMTAG_SIGPGP]))
if type(self.hdr[rpm.RPMTAG_HDRID]) is not types.NoneType:
   t.append("".join(self.hdr[rpm.RPMTAG_HDRID]))
kcsum = misc.Checksums(checksums=[self.checksum_type])
kcsum.update("".join(t))
key = kcsum.hexdigest()

Checksum tag is build like a:

csumtag = '%s-%s-%s-%s' % (os.path.basename(self.localpath),
                           key, self.size, self.filetime)
# "basefilename-key-filesize-filemtime"
# E.g. "foo.rpm-xyz-123-456"

From the cachedir path and the checksum tag a filename is build like a:

csumfile = '%s/%s' % (self._cachedir, csumtag)

If the filename exists and its mtime is higher or equal to mtime of the file which hash is being calculated, then use the checksum from the file.

If the filename doesn't exit, the checksum is calculated and the file created.


Cache file format

Just string representation of a checksum (hexdigest) without newline etc.


Notes

A cache file has mode 0666 so users can share the cache