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 066D31382C5 for ; Mon, 25 May 2020 10:44:03 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 10B69E083D; Mon, 25 May 2020 10:44:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (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 EB442E083D for ; Mon, 25 May 2020 10:44:00 +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 DF37634F013 for ; Mon, 25 May 2020 10:43:58 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 833CE267 for ; Mon, 25 May 2020 10:43:56 +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: <1590402747.3794f21d3da7f182c85b63e87f0e073b5df3de18.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/tree.c X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 3794f21d3da7f182c85b63e87f0e073b5df3de18 X-VCS-Branch: master Date: Mon, 25 May 2020 10:43:56 +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: 154cc927-5df2-40bc-927f-95c2b0622178 X-Archives-Hash: 349970669bfa3fabdd0b3f68850e5c9c commit: 3794f21d3da7f182c85b63e87f0e073b5df3de18 Author: Fabian Groffen gentoo org> AuthorDate: Mon May 25 10:32:27 2020 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Mon May 25 10:32:27 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3794f21d libq/tree: have tree_read_file_binpkg populate some meta fields The SHA1 and SIZE fields might be necessary, so psuedo fill them in here, as we don't have a meta that contains them, except the file itself. Signed-off-by: Fabian Groffen gentoo.org> libq/tree.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libq/tree.c b/libq/tree.c index 7fbb739..d901fc6 100644 --- a/libq/tree.c +++ b/libq/tree.c @@ -17,6 +17,7 @@ #include "atom.h" #include "eat_file.h" +#include "hash.h" #include "rmspace.h" #include "scandirat.h" #include "set.h" @@ -982,10 +983,48 @@ static tree_pkg_meta * tree_read_file_binpkg(tree_pkg_ctx *pkg_ctx) { tree_pkg_meta *m = xzalloc(sizeof(tree_pkg_meta)); + int newfd = dup(pkg_ctx->fd); xpak_process_fd(pkg_ctx->fd, true, m, tree_read_file_binpkg_xpak_cb); pkg_ctx->fd = -1; /* closed by xpak_process_fd */ + /* fill in some properties which are not available, but would be in + * Packages, and used to verify the package ... this is somewhat + * fake, but allows to transparantly use a dir of binpkgs */ + if (newfd != -1) { + size_t fsize; + size_t needlen = 40 + 1 + 19 + 1; + size_t pos = (size_t)m->Q__eclasses_; + size_t len = (size_t)m->Q__md5_; + + if (len - pos < needlen) { + char *old_data = m->Q__data; + len += ((needlen / BUFSIZ) + 1) * BUFSIZ; + m->Q__data = xrealloc(m->Q__data, len); + m->Q__md5_ = (char *)len; + + /* re-position existing keys */ + if (old_data != NULL && m->Q__data != old_data) { + char **newdata = (char **)m; + int elems = sizeof(tree_pkg_meta) / sizeof(char *); + while (elems-- > 1) /* skip Q__data itself */ + if (newdata[elems] != NULL) + newdata[elems] = + m->Q__data + (newdata[elems] - old_data); + } + } + + m->Q_SHA1 = m->Q__data + pos; + m->Q_SIZE = m->Q_SHA1 + 40 + 1; + pos += needlen; + m->Q__eclasses_ = (char *)pos; + + lseek(newfd, 0, SEEK_SET); /* reposition at the whole file */ + if (hash_multiple_file_fd(newfd, NULL, m->Q_SHA1, NULL, NULL, + NULL, NULL, &fsize, HASH_SHA1) == 0) + snprintf(m->Q_SIZE, 19 + 1, "%zu", fsize); + } + return m; }