'Checks that the hashes and sizes of the files in ``RECORD`` are
matched by the files themselves. Returns a (possibly empty) list of
mismatches. Each entry in the mismatch list will be a tuple consisting
of the path, \'exists\', \'size\' or \'hash\' according to what didn\'t match
(existence is checked first, then size, then hash), the expected
value and the actual value.'

def check_installed_files(self):

    mismatches = []
    base = os.path.dirname(self.path)
    record_path = self.get_distinfo_file(u'RECORD')
    for (path, hash_value, size) in self.list_installed_files():
        if (not os.path.isabs(path)):
            path = os.path.join(base, path)
        if (path == record_path):
            continue
        if (not os.path.exists(path)):
            mismatches.append((path, u'exists', True, False))
        elif os.path.isfile(path):
            actual_size = str(os.path.getsize(path))
            if (size and (actual_size != size)):
                mismatches.append((path, u'size', size, actual_size))
            elif hash_value:
                if (u'=' in hash_value):
                    hasher = hash_value.split(u'=', 1)[0]
                else:
                    hasher = None
                with open(path, u'rb') as f:
                    actual_hash = self.get_hash(f.read(), hasher)
                    if (actual_hash != hash_value):
                        mismatches.append((path, u'hash', hash_value, actual_hash))
    return mismatches
