Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/agama-software/src/model/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ impl From<ResolvableSelection> for zypp_agama::ResolvableSelected {
#[derive(Default, Debug)]
pub struct SoftwareOptions {
/// Install only required packages (not recommended ones).
only_required: bool,
pub only_required: bool,
}

#[derive(Clone, Debug)]
Expand Down
24 changes: 18 additions & 6 deletions rust/agama-software/src/zypp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub struct ZyppServer {
install_dir: Utf8PathBuf,
trusted_keys: Vec<RepoKey>,
unsigned_repos: Vec<String>,
only_required: bool,
}

impl ZyppServer {
Expand All @@ -148,6 +149,7 @@ impl ZyppServer {
registration: Default::default(),
trusted_keys: vec![],
unsigned_repos: vec![],
only_required: false,
};

// drop the returned JoinHandle: the thread will be detached
Expand Down Expand Up @@ -438,8 +440,10 @@ impl ZyppServer {
};
}

self.only_required = state.options.only_required;
tracing::info!("Install only required packages: {}", self.only_required);
// run the solver to select the dependencies, ignore the errors, the solver runs again later
let _ = zypp.run_solver();
let _ = zypp.run_solver(self.only_required);

// unselect packages including the autoselected dependencies
for (name, r#type, selection) in &state.resolvables.to_vec() {
Expand All @@ -450,7 +454,7 @@ impl ZyppServer {
}

_ = progress.cast(progress::message::Finish::new(Scope::Software));
match zypp.run_solver() {
match zypp.run_solver(self.only_required) {
Ok(result) => println!("Solver result: {result}"),
Err(error) => println!("Solver failed: {error}"),
};
Expand Down Expand Up @@ -513,7 +517,8 @@ impl ZyppServer {
return Ok(());
}
let _ = self.registration_finish(); // TODO: move it outside of zypp server as it do not need zypp lock
let _ = self.modify_zypp_conf(); // TODO: move it outside of zypp server as it do not need zypp lock

self.modify_zypp_conf();

if let Err(error) = self.modify_full_repo(zypp) {
tracing::warn!("Failed to modify the full repository: {error}");
Expand Down Expand Up @@ -597,9 +602,16 @@ impl ZyppServer {
Ok(())
}

fn modify_zypp_conf(&self) -> ZyppServerResult<()> {
// TODO: implement when requireOnly is implemented
Ok(())
fn modify_zypp_conf(&self) {
// write only if different from default
if self.only_required {
let contents = "# Use only hard dependencies as configured in installer\nsolver.onlyRequires = true\n";
let path = self.install_dir.join("etc/zypp/zypp.conf.d/installer.conf");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: in other .d directories, the name of the files is usually prefixed with a number (50-installer.conf). Is that expected in this case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to mention it also here. I use basically format from example from libzypp developer who use for micro os micro.conf without any number.

let write_result = std::fs::write(path.as_path(), contents);
if write_result.is_err() {
tracing::error!("Failed to write {path}: {write_result:?}");
}
}
}

fn system_info(
Expand Down
7 changes: 7 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jan 29 21:10:18 UTC 2026 - Josef Reidinger <jreidinger@suse.com>

- Add support for "onlyRequired" key in "software" section
using new libzypp zypp.conf.d directory.
(gh#agama-project/agama#3100)

-------------------------------------------------------------------
Thu Jan 29 14:56:50 UTC 2026 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
4 changes: 2 additions & 2 deletions rust/zypp-agama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,11 @@ impl Zypp {
}
}

pub fn run_solver(&self) -> ZyppResult<bool> {
pub fn run_solver(&self, only_required: bool) -> ZyppResult<bool> {
unsafe {
let mut status: Status = Status::default();
let status_ptr = &mut status as *mut _;
let r_res = zypp_agama_sys::run_solver(self.ptr, status_ptr);
let r_res = zypp_agama_sys::run_solver(self.ptr, only_required, status_ptr);
helpers::status_to_result(status, r_res)
}
}
Expand Down
4 changes: 3 additions & 1 deletion rust/zypp-agama/zypp-agama-sys/c-layer/include/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ bool is_package_selected(struct Zypp *zypp, const char *tag,

/// Runs solver
/// @param zypp see \ref init_target
/// @param only_required if true, only required packages are installed (ignoring recommended packages)
/// @param[out] status (will overwrite existing contents)
/// @return true if solver pass and false if it found some dependency issues
bool run_solver(struct Zypp *zypp, struct Status *status) noexcept;
bool run_solver(struct Zypp *zypp, bool only_required,
struct Status *status) noexcept;

/// the last call that will free all pointers to zypp holded by agama
void free_zypp(struct Zypp *zypp) noexcept;
Expand Down
8 changes: 4 additions & 4 deletions rust/zypp-agama/zypp-agama-sys/c-layer/include/repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ extern "C" {
#endif

struct Repository {
bool enabled; ///<
char *url; ///< owned
char *alias; ///< owned
char *userName; ///< owned
bool enabled; ///<
char *url; ///< owned
char *alias; ///< owned
char *userName; ///< owned
char *serviceName; ///< owned
};

Expand Down
7 changes: 5 additions & 2 deletions rust/zypp-agama/zypp-agama-sys/c-layer/lib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ struct PatternInfos get_patterns_info(struct Zypp *_zypp,
break;
}
} else {
// distinguish between the "not selected" and "explicitly removed by user" states
// distinguish between the "not selected" and "explicitly removed by user"
// states
if (status.getTransactByValue() == zypp::ResStatus::TransactByValue::USER)
result.infos[i].selected = RESOLVABLE_SELECTED::USER_REMOVED;
else
Expand All @@ -423,9 +424,11 @@ void free_pattern_infos(const struct PatternInfos *infos) noexcept {
free(infos->infos);
}

bool run_solver(struct Zypp *zypp, struct Status *status) noexcept {
bool run_solver(struct Zypp *zypp, bool only_required,
struct Status *status) noexcept {
try {
STATUS_OK(status);
zypp->zypp_pointer->resolver()->setOnlyRequires(only_required);
return zypp->zypp_pointer->resolver()->resolvePool();
} catch (zypp::Exception &excpt) {
STATUS_EXCEPT(status, excpt);
Expand Down
4 changes: 2 additions & 2 deletions rust/zypp-agama/zypp-agama-sys/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ unsafe extern "C" {
tag: *const ::std::os::raw::c_char,
status: *mut Status,
) -> bool;
#[doc = " Runs solver\n @param zypp see \\ref init_target\n @param[out] status (will overwrite existing contents)\n @return true if solver pass and false if it found some dependency issues"]
pub fn run_solver(zypp: *mut Zypp, status: *mut Status) -> bool;
#[doc = " Runs solver\n @param zypp see \\ref init_target\n @param only_required if true, only required packages are installed (ignoring recommended packages)\n @param[out] status (will overwrite existing contents)\n @return true if solver pass and false if it found some dependency issues"]
pub fn run_solver(zypp: *mut Zypp, only_required: bool, status: *mut Status) -> bool;
#[doc = " the last call that will free all pointers to zypp holded by agama"]
pub fn free_zypp(zypp: *mut Zypp);
#[doc = " repository array in list.\n when no longer needed, use \\ref free_repository_list to release memory\n @param zypp see \\ref init_target\n @param[out] status (will overwrite existing contents)"]
Expand Down
Loading