Skip to content

Commit 24424a1

Browse files
authored
Merge pull request #585 from AOSC-Dev/new-apt-solver-by-default
2 parents e089354 + 1ffae20 commit 24424a1

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

oma-pm/src/apt.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ pub enum OmaAptError {
113113
#[error("Failed to mark package for reinstallation: {0}")]
114114
MarkReinstallError(String, String),
115115
#[error("Dependencies unmet")]
116-
DependencyIssue(Vec<Vec<BrokenPackage>>),
116+
DependencyIssue {
117+
broken_depndencies: Vec<Vec<BrokenPackage>>,
118+
is_solver3: bool,
119+
apt_errors: AptErrors,
120+
},
117121
#[error("Package: {0} is essential.")]
118122
PkgIsEssential(String),
119123
#[error("Package: {0} has no available candidate.")]
@@ -311,12 +315,20 @@ impl OmaApt {
311315
config.set_vector("Dpkg::Options::", &dpkg_args);
312316
debug!("dpkg args: {dpkg_args:?}");
313317

314-
for kv in another_apt_options {
315-
let (k, v) = kv.split_once('=').unwrap_or((&kv, ""));
318+
for kv in &another_apt_options {
319+
let (k, v) = kv.split_once('=').unwrap_or((kv, ""));
316320
config.set(k, v);
317321
debug!("{k}={v} is set");
318322
}
319323

324+
#[cfg(feature = "aosc")]
325+
if another_apt_options
326+
.iter()
327+
.all(|kv| !kv.starts_with("APT::Solver"))
328+
{
329+
config.set("APT::Solver", "3.0");
330+
}
331+
320332
Ok(config)
321333
}
322334

@@ -710,7 +722,11 @@ impl OmaApt {
710722
self.unmet.extend(res);
711723
}
712724
}
713-
return Err(OmaAptError::DependencyIssue(self.unmet.to_vec()));
725+
return Err(OmaAptError::DependencyIssue {
726+
broken_depndencies: self.unmet.to_vec(),
727+
is_solver3: self.config.get("APT::Solver").is_some_and(|v| v == "3.0"),
728+
apt_errors: e,
729+
});
714730
}
715731

716732
Ok(())

src/error.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,34 @@ pub fn oma_apt_error_to_output(err: OmaAptError) -> OutputError {
661661
description: fl!("can-not-mark-reinstall", name = pkg, version = version),
662662
source: None,
663663
},
664-
OmaAptError::DependencyIssue(ref broken_deps) => {
664+
OmaAptError::DependencyIssue {
665+
broken_depndencies: broken_deps,
666+
is_solver3,
667+
apt_errors,
668+
} => {
665669
error!("{}", fl!("dep-issue-1"));
670+
debug!("{:#?}", broken_deps);
666671

667-
if !broken_deps.is_empty() {
672+
if is_solver3 {
673+
let mut errs = vec![];
674+
675+
for err in apt_errors.iter() {
676+
if !errs.contains(&err.msg) {
677+
errs.push(err.msg.to_string());
678+
}
679+
}
680+
681+
#[cfg(feature = "aosc")]
682+
if !errs.is_empty() {
683+
info!("{}", fl!("dep-issue-2"));
684+
}
685+
686+
eprintln!();
687+
688+
for err in errs {
689+
msg!("{err}");
690+
}
691+
} else if !broken_deps.is_empty() {
668692
let name_len_max = broken_deps
669693
.iter()
670694
.filter(|dep| !dep.is_empty())
@@ -683,7 +707,7 @@ pub fn oma_apt_error_to_output(err: OmaAptError) -> OutputError {
683707

684708
let mut last_name = "";
685709

686-
for dep in broken_deps {
710+
for dep in &broken_deps {
687711
let mut prefix = String::new();
688712
if last_name != dep[0].name {
689713
prefix = format!("{}:", dep[0].name);

0 commit comments

Comments
 (0)