From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 7183D1382C5 for ; Sun, 17 May 2020 12:35:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8AE9CE091A; Sun, 17 May 2020 12:35:46 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 647B1E091A for ; Sun, 17 May 2020 12:35:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 88F6E34F89F for ; Sun, 17 May 2020 12:35:45 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 9F36E250 for ; Sun, 17 May 2020 12:35:42 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1589718856.65ffc8ca7cb62140e281ce80918d19e9cc64a43e.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qmerge.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 65ffc8ca7cb62140e281ce80918d19e9cc64a43e X-VCS-Branch: master Date: Sun, 17 May 2020 12:35:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 36b9f59b-cd94-493f-97af-85a276cab992 X-Archives-Hash: 5edc10e0f89e4b5e18e9fdaa36a839ec commit: 65ffc8ca7cb62140e281ce80918d19e9cc64a43e Author: Fabian Groffen gentoo org> AuthorDate: Sun May 17 12:34:16 2020 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sun May 17 12:34:16 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=65ffc8ca qmerge: calculate MD5/SHA1 hashes possibly in parallel take advantage of libq/hash's interface to parallelise hash computation if possible Signed-off-by: Fabian Groffen gentoo.org> qmerge.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/qmerge.c b/qmerge.c index e86ce00..087c5f2 100644 --- a/qmerge.c +++ b/qmerge.c @@ -1598,34 +1598,51 @@ unlink_empty(const char *buf) } static int -pkg_verify_checksums(char *fname, const struct pkg_t *pkg, const depend_atom *atom, - int strict, int display) +pkg_verify_checksums( + char *fname, + const struct pkg_t *pkg, + const depend_atom *atom, + int strict, + int display) { - char *hash = NULL; int ret = 0; + char md5[32+1]; + char sha1[40+1]; + size_t flen; + + if (hash_multiple_file(fname, md5, sha1, NULL, NULL, NULL, NULL, + &flen, HASH_MD5 | HASH_SHA1) == -1) + errf("failed to compute hashes for %s/%s: %s\n", + atom->CATEGORY, pkg->PF, strerror(errno)); + + if (flen != pkg->SIZE) { + warn("filesize %zu doesn't match requested size %zu for %s/%s\n", + flen, pkg->SIZE, atom->CATEGORY, pkg->PF); + ret++; + } if (pkg->MD5[0]) { - if ((hash = hash_file(fname, HASH_MD5)) == NULL) { - errf("hash is NULL for %s", fname); - } - if (strcmp(hash, pkg->MD5) == 0) { + if (md5 != NULL && strcmp(md5, pkg->MD5) == 0) { if (display) - printf("MD5: [%sOK%s] %s %s/%s\n", GREEN, NORM, hash, atom->CATEGORY, pkg->PF); + printf("MD5: [%sOK%s] %s %s/%s\n", + GREEN, NORM, md5, atom->CATEGORY, pkg->PF); } else { if (display) - warn("MD5: [%sER%s] (%s) != (%s) %s/%s", RED, NORM, hash, pkg->MD5, atom->CATEGORY, pkg->PF); + warn("MD5: [%sER%s] (%s) != (%s) %s/%s", + RED, NORM, md5, pkg->MD5, atom->CATEGORY, pkg->PF); ret++; } } - if (pkg->SHA1[0]) { - hash = hash_file(fname, HASH_SHA1); - if (strcmp(hash, pkg->SHA1) == 0) { + if (sha1 != NULL && pkg->SHA1[0]) { + if (strcmp(sha1, pkg->SHA1) == 0) { if (display) - qprintf("SHA1: [%sOK%s] %s %s/%s\n", GREEN, NORM, hash, atom->CATEGORY, pkg->PF); + qprintf("SHA1: [%sOK%s] %s %s/%s\n", + GREEN, NORM, sha1, atom->CATEGORY, pkg->PF); } else { if (display) - warn("SHA1: [%sER%s] (%s) != (%s) %s/%s", RED, NORM, hash, pkg->SHA1, atom->CATEGORY, pkg->PF); + warn("SHA1: [%sER%s] (%s) != (%s) %s/%s", + RED, NORM, sha1, pkg->SHA1, atom->CATEGORY, pkg->PF); ret++; } }