def validate_layer(self, layer): ret = [] layer = layer.replace("sha256:", "") repo = self._get_ostree_repo() if not repo: return ret def validate_ostree_file(csum): _, inputfile, file_info, xattrs = repo.load_file(csum) # images are imported from layer tarballs, without any xattr. Don't use xattr to compute # the OSTree object checksum. xattrs = GLib.Variant("a(ayay)", []) _, checksum_v = OSTree.checksum_file_from_input(file_info, xattrs, inputfile, OSTree.ObjectType.FILE) return OSTree.checksum_from_bytes(checksum_v) def traverse(it): def get_out_content_checksum(obj): return obj.out_content_checksum if hasattr(obj, 'out_content_checksum') else obj[1] def get_out_checksum(obj): return obj.out_checksum if hasattr(obj, 'out_checksum') else obj[1] while True: res = it.next() # pylint: disable=next-method-called if res == OSTree.RepoCommitIterResult.DIR: dir_checksum = get_out_content_checksum(it.get_dir()) dir_it = OSTree.RepoCommitTraverseIter() dirtree = repo.load_variant(OSTree.ObjectType.DIR_TREE, dir_checksum) dir_it.init_dirtree(repo, dirtree[1], OSTree.RepoCommitTraverseFlags.REPO_COMMIT_TRAVERSE_FLAG_NONE) traverse(dir_it) elif res == OSTree.RepoCommitIterResult.FILE: new_checksum = validate_ostree_file(get_out_checksum(it.get_file())) if new_checksum != get_out_checksum(it.get_file()): ret.append({"name" : it.get_file().out_name, "old-checksum" : it.get_file().out_checksum, "new-checksum" : new_checksum}) elif res == OSTree.RepoCommitIterResult.ERROR: raise ValueError("Internal error while validating the layer") elif res == OSTree.RepoCommitIterResult.END: break current_rev = repo.resolve_rev("%s%s" % (OSTREE_OCIIMAGE_PREFIX, layer), False)[1] it = OSTree.RepoCommitTraverseIter() it.init_commit(repo, repo.load_commit(current_rev)[1], OSTree.RepoCommitTraverseFlags.REPO_COMMIT_TRAVERSE_FLAG_NONE) traverse(it) return ret
def traverse(it): def get_out_content_checksum(obj): return obj.out_content_checksum if hasattr(obj, 'out_content_checksum') else obj[1] def get_out_checksum(obj): return obj.out_checksum if hasattr(obj, 'out_checksum') else obj[1] while True: res = it.next() # pylint: disable=next-method-called if res == OSTree.RepoCommitIterResult.DIR: dir_checksum = get_out_content_checksum(it.get_dir()) dir_it = OSTree.RepoCommitTraverseIter() dirtree = repo.load_variant(OSTree.ObjectType.DIR_TREE, dir_checksum) dir_it.init_dirtree(repo, dirtree[1], OSTree.RepoCommitTraverseFlags.REPO_COMMIT_TRAVERSE_FLAG_NONE) traverse(dir_it) elif res == OSTree.RepoCommitIterResult.FILE: new_checksum = validate_ostree_file(get_out_checksum(it.get_file())) if new_checksum != get_out_checksum(it.get_file()): ret.append({"name" : it.get_file().out_name, "old-checksum" : it.get_file().out_checksum, "new-checksum" : new_checksum}) elif res == OSTree.RepoCommitIterResult.ERROR: raise ValueError("Internal error while validating the layer") elif res == OSTree.RepoCommitIterResult.END: break