[pve-devel] [PATCH pve-rs 1/1] apt: avoid overwriting files that could not be parsed

Fabian Ebner f.ebner at proxmox.com
Thu Jul 1 09:54:00 CEST 2021


The enable/disable case should not be reachable via UI as the digest
check comes first, but it's still good to fix it too.

Reported-by: Dominik Csapak <d.csapak at proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/apt/repositories.rs | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/apt/repositories.rs b/src/apt/repositories.rs
index 3a421f0..26af67c 100644
--- a/src/apt/repositories.rs
+++ b/src/apt/repositories.rs
@@ -60,7 +60,7 @@ mod export {
     /// The `digest` parameter asserts that the configuration has not been modified.
     #[export]
     pub fn add_repository(handle: &str, digest: Option<&str>) -> Result<(), Error> {
-        let (mut files, _errors, current_digest) = proxmox_apt::repositories::repositories()?;
+        let (mut files, errors, current_digest) = proxmox_apt::repositories::repositories()?;
 
         if let Some(digest) = digest {
             let expected_digest = proxmox::tools::hex_to_digest(digest)?;
@@ -72,6 +72,14 @@ mod export {
         let (repo, path) =
             proxmox_apt::repositories::get_standard_repository(handle.try_into()?, "pve")?;
 
+        if let Some(error) = errors.iter().find(|error| error.path == path) {
+            bail!(
+                "unable to parse existing file {} - {}",
+                error.path,
+                error.error,
+            );
+        }
+
         if let Some(file) = files.iter_mut().find(|file| file.path == path) {
             file.repositories.push(repo);
 
@@ -100,7 +108,7 @@ mod export {
         options: ChangeProperties,
         digest: Option<&str>,
     ) -> Result<(), Error> {
-        let (mut files, _errors, current_digest) = proxmox_apt::repositories::repositories()?;
+        let (mut files, errors, current_digest) = proxmox_apt::repositories::repositories()?;
 
         if let Some(digest) = digest {
             let expected_digest = proxmox::tools::hex_to_digest(digest)?;
@@ -109,6 +117,10 @@ mod export {
             }
         }
 
+        if let Some(error) = errors.iter().find(|error| error.path == path) {
+            bail!("unable to parse file {} - {}", error.path, error.error);
+        }
+
         if let Some(file) = files.iter_mut().find(|file| file.path == path) {
             if let Some(repo) = file.repositories.get_mut(index) {
                 if let Some(enabled) = options.enabled {
-- 
2.30.2






More information about the pve-devel mailing list