]> git.proxmox.com Git - proxmox-offline-mirror.git/commitdiff
fix #4259: mirror: add ignore-errors option
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 23 Sep 2022 10:33:51 +0000 (12:33 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 23 Sep 2022 12:18:03 +0000 (14:18 +0200)
to make fetching errors from broken repositories non-fatal.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/bin/proxmox-offline-mirror.rs
src/bin/proxmox_offline_mirror_cmds/config.rs
src/config.rs
src/mirror.rs

index 0a6e77effe7ae83e383308c7fe523749a9c72595..222b561b616cd198acaa03bfa9e453f2d05eb107 100644 (file)
@@ -386,6 +386,7 @@ fn action_add_mirror(config: &SectionConfigData) -> Result<Vec<MirrorConfig>, Er
                 sync,
                 base_dir: base_dir.clone(),
                 use_subscription: None,
+                ignore_errors: false,
             });
         }
     }
@@ -399,6 +400,7 @@ fn action_add_mirror(config: &SectionConfigData) -> Result<Vec<MirrorConfig>, Er
         sync,
         base_dir,
         use_subscription,
+        ignore_errors: false,
     };
 
     configs.push(main_config);
index b48a70808072b9179cc9a3cf9783e2fefbc34295..5ebf6d5ac54819ae7c0696f07c147804d0887c7e 100644 (file)
@@ -262,6 +262,9 @@ pub fn update_mirror(
     if let Some(verify) = update.verify {
         data.verify = verify
     }
+    if let Some(ignore_errors) = update.ignore_errors {
+        data.ignore_errors = ignore_errors
+    }
 
     config.set_data(&id, "mirror", &data)?;
     proxmox_offline_mirror::config::save_config(&config_file, &config)?;
index 6c2f3e81b619fb3b84c12306678e881a65655a8c..cb9a22b5c6a79529d0be4a2092912a97735f2fed 100644 (file)
@@ -41,6 +41,11 @@ use crate::types::{
         sync: {
             type: bool,
         },
+        "ignore-errors": {
+            type: bool,
+            optional: true,
+            default: false,
+        },
     }
 )]
 #[derive(Clone, Debug, Serialize, Deserialize, Updater)]
@@ -65,6 +70,9 @@ pub struct MirrorConfig {
     /// Use subscription key to access (required for Proxmox Enterprise repositories).
     #[serde(skip_serializing_if = "Option::is_none")]
     pub use_subscription: Option<ProductType>,
+    /// Whether to downgrade download errors to warnings
+    #[serde(default)]
+    pub ignore_errors: bool,
 }
 
 #[api(
index 51263936b2fc5191e36804c9ff4907645481720b..25c6af6bf3804441b0541e6e48f6c51dc290f6dc 100644 (file)
@@ -46,6 +46,7 @@ struct ParsedMirrorConfig {
     pub sync: bool,
     pub auth: Option<String>,
     pub client: Client,
+    pub ignore_errors: bool,
 }
 
 impl TryInto<ParsedMirrorConfig> for MirrorConfig {
@@ -74,6 +75,7 @@ impl TryInto<ParsedMirrorConfig> for MirrorConfig {
             sync: self.sync,
             auth: None,
             client,
+            ignore_errors: self.ignore_errors,
         })
     }
 }
@@ -691,7 +693,7 @@ pub fn create_snapshot(
                 let mut full_path = PathBuf::from(prefix);
                 full_path.push(&package.file);
 
-                let res = fetch_plain_file(
+                match fetch_plain_file(
                     &config,
                     &url,
                     &full_path,
@@ -699,8 +701,19 @@ pub fn create_snapshot(
                     &package.checksums,
                     false,
                     dry_run,
-                )?;
-                fetch_progress.update(&res);
+                ) {
+                    Ok(res) => fetch_progress.update(&res),
+                    Err(err) if config.ignore_errors => {
+                        let msg = format!(
+                            "{}: failed to fetch package '{}' - {}",
+                            basename, package.file, err,
+                        );
+                        eprintln!("{msg}");
+                    }
+                    res => {
+                        res?;
+                    }
+                }
             }
 
             if fetch_progress.file_count() % (max(total_files / 100, 1)) == 0 {