From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1519089CC4 for ; Tue, 18 Oct 2022 11:21:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CEEB826AB3 for ; Tue, 18 Oct 2022 11:21:06 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 18 Oct 2022 11:21:05 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 12A2144A55 for ; Tue, 18 Oct 2022 11:21:05 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Tue, 18 Oct 2022 11:20:39 +0200 Message-Id: <20221018092040.860121-6-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221018092040.860121-1-f.gruenbichler@proxmox.com> References: <20221018092040.860121-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.142 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mirror.rs] Subject: [pve-devel] [PATCH proxmox-offline-mirror 3/4] fix #4264: only require either Release or InRelease X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Oct 2022 09:21:07 -0000 strictly speaking InRelease is required, and Release optional, but that might not be true for older repositories. treat failure to fetch either as non-fatal, provided the other is available. Signed-off-by: Fabian Grünbichler --- src/mirror.rs | 70 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/src/mirror.rs b/src/mirror.rs index 37dca97..39b7f47 100644 --- a/src/mirror.rs +++ b/src/mirror.rs @@ -144,40 +144,61 @@ fn fetch_repo_file( /// Helper to fetch InRelease (`detached` == false) or Release/Release.gpg (`detached` == true) files from repository. /// -/// Verifies the contained/detached signature, stores all fetched files under `prefix`, and returns the verified raw release file data. +/// Verifies the contained/detached signature and stores all fetched files under `prefix`. +/// +/// Returns the verified raw release file data, or None if the "fetch" part itself fails. fn fetch_release( config: &ParsedMirrorConfig, prefix: &Path, detached: bool, dry_run: bool, -) -> Result { +) -> Result, Error> { let (name, fetched, sig) = if detached { println!("Fetching Release/Release.gpg files"); - let sig = fetch_repo_file( + let sig = match fetch_repo_file( &config.client, &get_dist_url(&config.repository, "Release.gpg"), 1024 * 1024, None, config.auth.as_deref(), - )?; - let mut fetched = fetch_repo_file( + ) { + Ok(res) => res, + Err(err) => { + eprintln!("Release.gpg fetch failure: {err}"); + return Ok(None); + } + }; + + let mut fetched = match fetch_repo_file( &config.client, &get_dist_url(&config.repository, "Release"), 256 * 1024 * 1024, None, config.auth.as_deref(), - )?; + ) { + Ok(res) => res, + Err(err) => { + eprintln!("Release fetch failure: {err}"); + return Ok(None); + } + }; fetched.fetched += sig.fetched; ("Release(.gpg)", fetched, Some(sig.data())) } else { println!("Fetching InRelease file"); - let fetched = fetch_repo_file( + let fetched = match fetch_repo_file( &config.client, &get_dist_url(&config.repository, "InRelease"), 256 * 1024 * 1024, None, config.auth.as_deref(), - )?; + ) { + Ok(res) => res, + Err(err) => { + eprintln!("InRelease fetch failure: {err}"); + return Ok(None); + } + }; ("InRelease", fetched, None) }; @@ -193,10 +214,10 @@ fn fetch_release( }; if dry_run { - return Ok(FetchResult { + return Ok(Some(FetchResult { data: verified, fetched: fetched.fetched, - }); + })); } let locked = &config.pool.lock()?; @@ -230,10 +251,10 @@ fn fetch_release( )?; } - Ok(FetchResult { + Ok(Some(FetchResult { data: verified, fetched: fetched.fetched, - }) + })) } /// Helper to fetch an index file referenced by a `ReleaseFile`. @@ -510,14 +531,25 @@ pub fn create_snapshot( Ok(parsed) }; - // we want both on-disk for compat reasons - let res = fetch_release(&config, prefix, true, dry_run)?; - total_progress.update(&res); - let _release = parse_release(res, "Release")?; + // we want both on-disk for compat reasons, if both are available + let release = fetch_release(&config, prefix, true, dry_run)? + .map(|res| { + total_progress.update(&res); + parse_release(res, "Release") + }) + .transpose()?; + + let in_release = fetch_release(&config, prefix, false, dry_run)? + .map(|res| { + total_progress.update(&res); + parse_release(res, "InRelease") + }) + .transpose()?; - let res = fetch_release(&config, prefix, false, dry_run)?; - total_progress.update(&res); - let release = parse_release(res, "InRelease")?; + // at least one must be available to proceed + let release = release + .or(in_release) + .ok_or_else(|| format_err!("Neither Release(.gpg) nor InRelease available!"))?; let mut per_component = HashMap::new(); let mut others = Vec::new(); -- 2.30.2