-
Notifications
You must be signed in to change notification settings - Fork 74
add to C layer callbacks for download part of commit #2863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b520d86
6a4d1dc
b20b928
ed10278
6c3809e
a9ad574
5c23138
d482f2d
f06bdac
f1ebc09
db7ae47
37bc35d
6924082
e76ebdc
17a5e2a
1374c18
356cc18
347f269
66220a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod commit_download; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| use agama_utils::{actor::Handler, api::question::QuestionSpec, progress, question}; | ||
| use gettextrs::gettext; | ||
| use tokio::runtime::Handle; | ||
| use zypp_agama::callbacks::pkg_download::{Callback, DownloadError}; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct CommitDownload { | ||
| progress: Handler<progress::Service>, | ||
| questions: Handler<question::Service>, | ||
| } | ||
|
|
||
| impl CommitDownload { | ||
| pub fn new( | ||
| progress: Handler<progress::Service>, | ||
| questions: Handler<question::Service>, | ||
| ) -> Self { | ||
| Self { | ||
| progress, | ||
| questions, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Callback for CommitDownload { | ||
| fn start_preload(&self) { | ||
| // TODO: report progress that we start preloading packages | ||
| tracing::info!("Start preload"); | ||
| } | ||
|
|
||
| fn problem( | ||
| &self, | ||
| name: &str, | ||
| error: DownloadError, | ||
| description: &str, | ||
| ) -> zypp_agama::callbacks::ProblemResponse { | ||
| // TODO: make it generic for any problemResponse questions | ||
| let labels = [gettext("Retry"), gettext("Ignore")]; | ||
| let actions = [ | ||
| ("Retry", labels[0].as_str()), | ||
| ("Ignore", labels[1].as_str()), | ||
| ]; | ||
| let error_str = error.to_string(); | ||
| let data = [("package", name), ("error_code", error_str.as_str())]; | ||
| let question = QuestionSpec::new(description, "software.package_error.provide_error") | ||
| .with_actions(&actions) | ||
| .with_data(&data); | ||
| let result = Handle::current().block_on(async move { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NP: I feel the bottom half of the fn is boilerplate and we will want to factor it out as more callbacks appear
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I am sure that at least more helpers for ProblemResponse handling will be useful. So lets see how it will end.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I plan to revisit it when more callbacks appears |
||
| self.questions | ||
| .call(question::message::Ask::new(question)) | ||
| .await | ||
| }); | ||
| let Ok(answer) = result else { | ||
| tracing::warn!("Failed to ask question {:?}", result); | ||
| return zypp_agama::callbacks::ProblemResponse::ABORT; | ||
| }; | ||
|
|
||
| let Some(answer_str) = answer.answer else { | ||
| tracing::warn!("No answer provided"); | ||
| return zypp_agama::callbacks::ProblemResponse::ABORT; | ||
| }; | ||
|
|
||
| answer_str | ||
| .action | ||
| .as_str() | ||
| .parse::<zypp_agama::callbacks::ProblemResponse>() | ||
| .unwrap_or(zypp_agama::callbacks::ProblemResponse::ABORT) | ||
| } | ||
|
|
||
| fn gpg_check( | ||
| &self, | ||
| resolvable_name: &str, | ||
| _repo_url: &str, | ||
| check_result: zypp_agama::callbacks::pkg_download::GPGCheckResult, | ||
| ) -> Option<zypp_agama::callbacks::ProblemResponse> { | ||
| if check_result == zypp_agama::callbacks::pkg_download::GPGCheckResult::Ok { | ||
| // GPG is happy, so we are also happy and lets just continue | ||
| return None; | ||
| } | ||
|
|
||
| // do not log URL here as it can contain sensitive info and it is visible from other logs | ||
| tracing::warn!( | ||
| "GPG check failed for {:?} with {:?}", | ||
| resolvable_name, | ||
| check_result | ||
| ); | ||
|
|
||
| // TODO: implement the DUD case: | ||
| // DUD (Driver Update Disk) | ||
| // ignore the error when the package comes from the DUD repository and | ||
| // the DUD package GPG checks are disabled via a boot option | ||
| // | ||
| // if repo_url == Agama::Software::Manager.dud_repository_url && ignore_dud_packages_gpg_errors? { | ||
| // logger.info "Ignoring the GPG check failure for a DUD package" | ||
| // return Ok(ProblemResponse::IGNORE); | ||
| // } | ||
|
|
||
| None | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ edition = "2021" | |
| [dependencies] | ||
| zypp-agama-sys = { path="./zypp-agama-sys" } | ||
| url = "2.5.7" | ||
| tracing = "0.1.41" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ## Zypp Agama | ||
|
|
||
| crate which purpose is to have thin layer to libzypp for agama purpose. | ||
|
|
||
| ### How to Add New Libzypp Call | ||
|
|
||
| - at first create its C API in `zypp-agama-sys/c-layer/include` directory and write its implementation to cxx file. | ||
| - generate new FFI bindings (in low level, unsafe Rust), in `rust/zypp-agama-sys` by running cargo build | ||
| - write a (regular, safe) Rust wrapper, in `src` | ||
|
|
||
| ### Libzypp Notes | ||
|
|
||
| - libzypp is not thread safe | ||
| - for seeing how it works see yast2-pkg-bindings and zypper as some parameters in calls are ignored | ||
| - goal is to have thin layer close to libzypp and build logic on top of it in more advanced language | ||
|
|
||
| ### Interesting Resources | ||
|
|
||
| - https://doc.rust-lang.org/nomicon/ffi.html | ||
| - https://adventures.michaelfbryan.com/posts/rust-closures-in-ffi/ | ||
| - https://www.khoury.northeastern.edu/home/lth/larceny/notes/note7-ffi.html | ||
| - https://cliffle.com/blog/not-thread-safe/ ( interesting part how to ensure in rust that some data is not thread safe ) |
Uh oh!
There was an error while loading. Please reload this page.