[pve-devel] [PATCH proxmox] fix #5513: apt: do not assume that sources.list file exists

Fiona Ebner f.ebner at proxmox.com
Wed Jun 5 10:29:24 CEST 2024


Some users might want to switch to using only the newer .sources files
already, which Debian is going to switch to in the long run.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 proxmox-apt/src/repositories/mod.rs | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/proxmox-apt/src/repositories/mod.rs b/proxmox-apt/src/repositories/mod.rs
index 7bfe9cae..26e4192c 100644
--- a/proxmox-apt/src/repositories/mod.rs
+++ b/proxmox-apt/src/repositories/mod.rs
@@ -146,12 +146,21 @@ pub fn repositories() -> Result<Repositories, Error> {
 
     let sources_list_d_path = PathBuf::from(APT_SOURCES_LIST_DIRECTORY);
 
-    match APTRepositoryFile::new(sources_list_path) {
-        Ok(Some(mut file)) => match file.parse() {
-            Ok(()) => files.push(file),
-            Err(err) => errors.push(err),
-        },
-        _ => bail!("internal error with '{}'", APT_SOURCES_LIST_FILENAME),
+    if sources_list_path.exists() {
+        if sources_list_path.is_file() {
+            match APTRepositoryFile::new(sources_list_path) {
+                Ok(Some(mut file)) => match file.parse() {
+                    Ok(()) => files.push(file),
+                    Err(err) => errors.push(err),
+                },
+                _ => bail!("internal error with '{}'", APT_SOURCES_LIST_FILENAME),
+            }
+        } else {
+            errors.push(APTRepositoryFileError {
+                path: APT_SOURCES_LIST_FILENAME.to_string(),
+                error: "not a regular file!".to_string(),
+            });
+        }
     }
 
     if !sources_list_d_path.exists() {
-- 
2.39.2





More information about the pve-devel mailing list