all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-offline-mirror 3/4] fix #4264: only require either Release or InRelease
Date: Tue, 18 Oct 2022 11:20:39 +0200	[thread overview]
Message-ID: <20221018092040.860121-6-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20221018092040.860121-1-f.gruenbichler@proxmox.com>

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 <f.gruenbichler@proxmox.com>
---
 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<FetchResult, Error> {
+) -> Result<Option<FetchResult>, 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





  parent reply	other threads:[~2022-10-18  9:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18  9:20 [pve-devel] [PATCH-SERIES 0/6] proxmox-offline-mirror filtering & deb-src support Fabian Grünbichler
2022-10-18  9:20 ` [pve-devel] [PATCH proxmox-apt 1/2] packages file: add section field Fabian Grünbichler
2022-10-18  9:20 ` [pve-devel] [PATCH proxmox-apt 2/2] deb822: source index support Fabian Grünbichler
2022-10-18  9:20 ` [pve-devel] [PATCH proxmox-offline-mirror 1/4] mirror: add exclusion of packages/sections Fabian Grünbichler
2022-10-18  9:20 ` [pve-devel] [PATCH proxmox-offline-mirror 2/4] mirror: implement source packages mirroring Fabian Grünbichler
2022-10-18  9:20 ` Fabian Grünbichler [this message]
2022-10-18  9:20 ` [pve-devel] [PATCH proxmox-offline-mirror 4/4] mirror: refactor fetch_binary/source_packages Fabian Grünbichler
2022-10-20 12:49 ` [pve-devel] applied-series: [PATCH-SERIES 0/6] proxmox-offline-mirror filtering & deb-src support Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221018092040.860121-6-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal