From patchwork Mon Aug 24 23:00:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Jonglez X-Patchwork-Id: 1350732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bitsofnetworks.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=l6NQO/mQ; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bb7203wv7z9sTT for ; Tue, 25 Aug 2020 09:02:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yEDcUJiJwOlCXcD29VcxkTAXuZokyOM3KnNPPfyrrKs=; b=l6NQO/mQU1qdpZdXgkio9zd6p d7b5SklWuOUgR7HyK33FQIIs1jSgJ4xlASn5AuvJ2YXbMtameqaJVS0896E6DdASeh3YB5wiVSyzl LfswpcrJL0EuMNdPGkLnd8txp14bdbZm8C1kW2C216F8nnX8YJbwVeOX8mvsus4CmnRN2jbI6W24F cDZof2GXguIff9+nubcngANTF4+c4hUmUzuH+iYGtNq4nePZqSbms5D91ZfwezxwVd6wv5EYhU45u eLcQWIdsrGsxwiPEob1jI2ZDSgcj2ylcqlWDywyYDGONlhho81ozkI9na6hjCf1roIS30bFMLtbhA UFMjAukkw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kALSV-0008Mm-9j; Mon, 24 Aug 2020 23:00:59 +0000 Received: from mails.bitsofnetworks.org ([2001:912:1800:ff::131]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kALSK-0008Ii-Ni for openwrt-devel@lists.openwrt.org; Mon, 24 Aug 2020 23:00:51 +0000 Received: from [2001:912:1800::5c8] (helo=localhost.localdomain) by mails.bitsofnetworks.org with esmtp (Exim 4.89) (envelope-from ) id 1kALSG-000419-Vl; Tue, 25 Aug 2020 01:00:44 +0200 From: Baptiste Jonglez To: openwrt-devel@lists.openwrt.org Subject: [PATCH opkg 4/5] download: purge cached packages that have incorrect checksum Date: Tue, 25 Aug 2020 01:00:31 +0200 Message-Id: <20200824230032.492951-5-baptiste@bitsofnetworks.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200824230032.492951-1-baptiste@bitsofnetworks.org> References: <20200824230032.492951-1-baptiste@bitsofnetworks.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_190049_261577_2667C793 X-CRM114-Status: GOOD ( 15.37 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Baptiste Jonglez Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Baptiste Jonglez Before using a package from the cache, verify its size and checksum against a package index, and delete the package from the cache if they don't match. The install process will then proceed to download the "fixed" package as usual. This allows to cope with remote packages that are rebuilt while keeping the same version number as packages in the local cache. With this change, any outdated package in the local cache will be purged and the new version will be downloaded instead. This is mostly useful when running opkg on the host (e.g. in the imagebuilder). When running on a device, no cache is configured by default, so this change does nothing in that case. Fixes: FS#2690 Signed-off-by: Baptiste Jonglez --- libopkg/opkg_download.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index 175282c..3b79856 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -263,6 +263,8 @@ int opkg_download_pkg(pkg_t * pkg, const char *dir) char *stripped_filename; char *urlencoded_path; char *filename; + char *cache_name; + char *cache_location; if (pkg->src == NULL) { opkg_msg(ERROR, @@ -296,6 +298,23 @@ int opkg_download_pkg(pkg_t * pkg, const char *dir) sprintf_alloc(&local_filename, "%s/%s", dir, stripped_filename); pkg_set_string(pkg, PKG_LOCAL_FILENAME, local_filename); + /* Invalidate/remove cached package if it has an incorrect checksum. */ + if (conf->cache) { + cache_name = get_cache_filename(local_filename); + sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name); + free(cache_name); + if (file_exists(cache_location)) { + err = opkg_verify_integrity(pkg, cache_location); + if (err) { + opkg_msg(NOTICE, + "Removing %s from cache because it has incorrect checksum.\n", + pkg->name); + unlink(cache_location); + } + } + free(cache_location); + } + err = opkg_download_cache(url, local_filename); free(url);