From ed0aa7c3580ce5bb1a0e5f6522bc0702c64453b0 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 25 Nov 2024 17:50:39 +0100 Subject: [PATCH] add also remove repository call --- c-layer/include/lib.h | 7 +++++++ c-layer/lib.cxx | 20 ++++++++++++++++++++ rust/zypp-agama-sys/src/bindings.rs | 7 +++++++ rust/zypp-agama/src/lib.rs | 15 +++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/c-layer/include/lib.h b/c-layer/include/lib.h index 3d48ab5..eed78f8 100644 --- a/c-layer/include/lib.h +++ b/c-layer/include/lib.h @@ -67,6 +67,13 @@ void free_repository_list(struct RepositoryList *repo_list) noexcept; /// @param user_data void add_repository(const char* alias, const char* url, struct Status *status, ZyppProgressCallback callback, void* user_data) noexcept; +/// Removes repository from repo manager +/// @param alias have to be unique +/// @param[out] status (will overwrite existing contents) +/// @param callback pointer to function with callback or NULL +/// @param user_data +void remove_repository(const char* alias, struct Status *status, ZyppProgressCallback callback, void* user_data) noexcept; + /// /// @param alias alias of repository to refresh /// @param[out] status (will overwrite existing contents) diff --git a/c-layer/lib.cxx b/c-layer/lib.cxx index e9e0d03..484fe25 100644 --- a/c-layer/lib.cxx +++ b/c-layer/lib.cxx @@ -172,6 +172,26 @@ void add_repository(const char* alias, const char* url, struct Status *status, Z } } +void remove_repository(const char* alias, struct Status *status, ZyppProgressCallback callback, void* user_data) noexcept { + if (repo_manager == NULL) { + status->state = status->STATE_FAILED; + status->error = strdup("Internal Error: Repo manager is not initialized."); + return; + } + try { + auto zypp_callback = create_progress_callback(callback, user_data); + zypp::RepoInfo zypp_repo = zypp::RepoInfo(); + zypp_repo.setAlias(alias); // alias should be unique, so it should always match correct repo + + repo_manager->removeRepository(zypp_repo,zypp_callback); + status->state = status->STATE_SUCCEED; + status->error = NULL; + } catch (zypp::Exception &excpt) { + status->state = status->STATE_FAILED; + status->error = strdup(excpt.asUserString().c_str()); + } +} + struct RepositoryList list_repositories() noexcept { if (repo_manager == NULL) { // TODO: error reporting? diff --git a/rust/zypp-agama-sys/src/bindings.rs b/rust/zypp-agama-sys/src/bindings.rs index fdca5aa..5f3a602 100644 --- a/rust/zypp-agama-sys/src/bindings.rs +++ b/rust/zypp-agama-sys/src/bindings.rs @@ -176,6 +176,13 @@ extern "C" { callback: ZyppProgressCallback, user_data: *mut ::std::os::raw::c_void, ); + #[doc = " Removes repository from repo manager\n @param alias have to be unique\n @param[out] status (will overwrite existing contents)\n @param callback pointer to function with callback or NULL\n @param user_data"] + pub fn remove_repository( + alias: *const ::std::os::raw::c_char, + status: *mut Status, + callback: ZyppProgressCallback, + user_data: *mut ::std::os::raw::c_void, + ); #[doc = "\n @param alias alias of repository to refresh\n @param[out] status (will overwrite existing contents)\n @param callbacks pointer to struct with callbacks or NULL if no progress is needed"] pub fn refresh_repository( alias: *const ::std::os::raw::c_char, diff --git a/rust/zypp-agama/src/lib.rs b/rust/zypp-agama/src/lib.rs index 4ce5248..50d2281 100644 --- a/rust/zypp-agama/src/lib.rs +++ b/rust/zypp-agama/src/lib.rs @@ -133,6 +133,21 @@ where } } +pub fn remove_repository(alias: &str, progress: F) -> Result<(), ZyppError> +where + F: FnMut(i64, String) -> bool, +{ + unsafe { + let mut closure = progress; + let cb = get_zypp_progress_callback(&closure); + let mut status: Status = Status { state: Status_STATE_STATE_SUCCEED, error: null_mut() }; + let status_ptr = &mut status as *mut _ as *mut Status; + let c_alias = CString::new(alias).unwrap(); + zypp_agama_sys::remove_repository(c_alias.as_ptr(), status_ptr, cb, &mut closure as *mut _ as *mut c_void); + return helpers::status_to_result_void(status); + } +} + #[cfg(test)] mod tests { use super::*;