From patchwork Mon Aug 24 23:00:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Jonglez X-Patchwork-Id: 1350729 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=WPfZsNlQ; 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 4Bb71z3gjdz9sSP for ; Tue, 25 Aug 2020 09:02:47 +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=SIUJ5XvRw6IEg18/+LADCxQW2A12fzOs3/n2Tw3QIi4=; b=WPfZsNlQUUNJd23ADKqu37Ocq qFoBxTFrUp9QE3je7M3tWj64rA80inCRNBfr9d+5CVs7IvQlB8/lxCNBEDZM78SjFtAb3XQh6tbmI DTysRhf1GZpFVP+oKkvOF8+obSIyTUKLEHa4XW6KOrxOFx0NT/J6Tfx9xnNK2JJE4Jg2uBIE0fvPp OF9q83VBLmhBxtij7Q5aY0m36vUm5TwLVwZf6OflaJ9tU27QrSklePziCRVZ6BZmv3BDtFEyCTu31 HG8DNRgNislBcJ5vhrXYVQmtBO1ckuCB2naGberFQElbrrJQ0fvkZobzZY811I2hrf63U9iH8c9Lq VCvSPU7Fg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kALSS-0008MJ-HH; Mon, 24 Aug 2020 23:00:56 +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-0008Ih-Nh 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-Pa; Tue, 25 Aug 2020 01:00:44 +0200 From: Baptiste Jonglez To: openwrt-devel@lists.openwrt.org Subject: [PATCH opkg 1/5] download: remove compatibility with old cache naming scheme Date: Tue, 25 Aug 2020 01:00:28 +0200 Message-Id: <20200824230032.492951-2-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_276778_56CDA38A X-CRM114-Status: GOOD ( 15.61 ) 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 A long time ago, the name of cached files was derived from the source URL. This was changed in 2011 with d46db43e21 ("Don't include the source URI in the cached filename.") Some compatibility code was left behind: even today, we are still trying to read from the old filename. The goal of this compatibility code was to account for existing caches that still had files with the old naming scheme. More than 9 years later, it is safe to remove this compatibility code. It simplifies the download code and avoids a useless disk access. Signed-off-by: Baptiste Jonglez --- libopkg/opkg_download.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index e970506..97df37f 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -131,8 +131,7 @@ opkg_download(const char *src, const char *dest_file_name, static int opkg_download_cache(const char *src, const char *dest_file_name) { - char *cache_name = xstrdup(src); - char *cache_location, *p; + char *cache_name, *cache_location; int err = 0; if (!conf->cache || str_starts_with(src, "file:")) { @@ -146,32 +145,19 @@ opkg_download_cache(const char *src, const char *dest_file_name) goto out1; } - for (p = cache_name; *p; p++) - if (*p == '/') - *p = ','; /* looks nicer than | or # */ - + char *filename = strrchr(dest_file_name, '/'); + if (filename) + cache_name = xstrdup(filename + 1); // strip leading '/' + else + cache_name = xstrdup(dest_file_name); sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name); if (file_exists(cache_location)) opkg_msg(NOTICE, "Copying %s.\n", cache_location); else { - /* cache file with funky name not found, try simple name */ - free(cache_name); - char *filename = strrchr(dest_file_name, '/'); - if (filename) - cache_name = xstrdup(filename + 1); // strip leading '/' - else - cache_name = xstrdup(dest_file_name); - free(cache_location); - sprintf_alloc(&cache_location, "%s/%s", conf->cache, - cache_name); - if (file_exists(cache_location)) - opkg_msg(NOTICE, "Copying %s.\n", cache_location); - else { - err = opkg_download(src, cache_location, 0); - if (err) { - (void)unlink(cache_location); - goto out2; - } + err = opkg_download(src, cache_location, 0); + if (err) { + (void)unlink(cache_location); + goto out2; } } @@ -179,8 +165,8 @@ opkg_download_cache(const char *src, const char *dest_file_name) out2: free(cache_location); -out1: free(cache_name); +out1: return err; }