[pve-devel] [PATCH pve-rs] apt: check if repository is already configured before adding
Fabian Ebner
f.ebner at proxmox.com
Thu Jul 1 11:01:40 CEST 2021
and if it is, enable it.
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
src/apt/repositories.rs | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/apt/repositories.rs b/src/apt/repositories.rs
index 26af67c..79c2334 100644
--- a/src/apt/repositories.rs
+++ b/src/apt/repositories.rs
@@ -6,7 +6,8 @@ mod export {
use serde::{Deserialize, Serialize};
use proxmox_apt::repositories::{
- APTRepositoryFile, APTRepositoryFileError, APTRepositoryInfo, APTStandardRepository,
+ APTRepositoryFile, APTRepositoryFileError, APTRepositoryHandle, APTRepositoryInfo,
+ APTStandardRepository,
};
#[derive(Deserialize, Serialize)]
@@ -56,12 +57,15 @@ mod export {
}
/// Add the repository identified by the `handle`.
+ /// If the repository is already configured, it will be set to enabled.
///
/// 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 handle: APTRepositoryHandle = handle.try_into()?;
+
if let Some(digest) = digest {
let expected_digest = proxmox::tools::hex_to_digest(digest)?;
if expected_digest != current_digest {
@@ -69,8 +73,23 @@ mod export {
}
}
- let (repo, path) =
- proxmox_apt::repositories::get_standard_repository(handle.try_into()?, "pve")?;
+ // check if it's already configured first
+ for file in files.iter_mut() {
+ for repo in file.repositories.iter_mut() {
+ if repo.is_referenced_repository(handle, "pve") {
+ if repo.enabled {
+ return Ok(());
+ }
+
+ repo.set_enabled(true);
+ file.write()?;
+
+ return Ok(());
+ }
+ }
+ }
+
+ let (repo, path) = proxmox_apt::repositories::get_standard_repository(handle, "pve")?;
if let Some(error) = errors.iter().find(|error| error.path == path) {
bail!(
--
2.30.2
More information about the pve-devel
mailing list