Skip to content

Commit

Permalink
add also remove repository call
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 25, 2024
1 parent bd1ab4e commit ed0aa7c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions c-layer/include/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions c-layer/lib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
7 changes: 7 additions & 0 deletions rust/zypp-agama-sys/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions rust/zypp-agama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ where
}
}

pub fn remove_repository<F>(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::*;
Expand Down

0 comments on commit ed0aa7c

Please sign in to comment.