Packagers files are OK if any one executor succeed

This commit is contained in:
Zykino 2023-07-12 00:06:28 +02:00
parent e0fe3620ca
commit 8d424e6c6a
6 changed files with 56 additions and 38 deletions

View File

@ -16,3 +16,14 @@ executors:
params: params:
- apt - apt
- autoremove - autoremove
- name: Zypper
pre_install:
- exe: sudo
params:
- zypper
- refresh
install:
exe: sudo
params:
- zypper
- dup

View File

@ -0,0 +1,7 @@
executors:
- name: Cargo
install:
exe: cargo
params:
- install-update
- -a

View File

@ -4,9 +4,3 @@ executors:
exe: rustup exe: rustup
params: params:
- update - update
- name: Cargo
install:
exe: cargo
params:
- install-update
- -a

View File

@ -98,7 +98,7 @@ pub fn get_packages_folder(opt: &Opt) -> io::Result<PathBuf> {
impl Updater { impl Updater {
fn new() -> Updater { fn new() -> Updater {
Updater { Updater {
packagers: BTreeMap::from([(String::new(), Packager { executors: vec![] })]), packagers: BTreeMap::default(),
} }
} }
@ -218,11 +218,25 @@ impl Updater {
// XXX: We may parallelise (iter_par from rayon?) this loop. But the UI will be problematic to handle // XXX: We may parallelise (iter_par from rayon?) this loop. But the UI will be problematic to handle
for (_packager_name, packager) in &self.packagers { for (_packager_name, packager) in &self.packagers {
// TODO: default status should be an error, but… in the same time we should not have en empty list
let mut stat = (String::from("No command"), Ok(()).into());
assert!(!packager.executors.is_empty());
for pkg in &packager.executors { for pkg in &packager.executors {
status.push((pkg.name.clone(), self.update(&pkg, opt).into())); let u = self.update(&pkg, opt);
let is_ok = u.is_ok();
stat = (pkg.name.clone(), u.into());
if is_ok {
break;
} }
} }
status.push(stat);
}
Summary { status } Summary { status }
} }
@ -256,7 +270,7 @@ impl Executor {
})?; })?;
if !exit_status.success() { if !exit_status.success() {
return Err(Error::Execution { return Result::Err(Error::Execution {
source: io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)), source: io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)),
step: UpdateSteps::PreInstall, step: UpdateSteps::PreInstall,
cmd, cmd,

View File

@ -8,6 +8,26 @@ use thiserror::Error;
pub type Result<T> = result::Result<T, Error>; pub type Result<T> = result::Result<T, Error>;
/// Result wrapper used to easily `Display` the Status of an execution
pub struct Status {
result: Result<()>,
}
impl Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Status { result: Ok(_) } => write!(f, "Ok"),
Status { result: Err(e) } => write!(f, "Error: {}", e),
}
}
}
impl From<Result<()>> for Status {
fn from(result: Result<()>) -> Self {
Status { result }
}
}
/// An error that can occur in this crate. /// An error that can occur in this crate.
/// ///
/// Generally, this error corresponds to problems with underlying process. /// Generally, this error corresponds to problems with underlying process.

View File

@ -21,35 +21,7 @@ pub struct Opt {
pub steps: Vec<UpdateSteps>, pub steps: Vec<UpdateSteps>,
} }
enum Status {
/// All steps asked were successful
Ok,
Err(Error),
}
impl Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Status::Ok => write!(f, "Ok"),
Status::Err(e) => write!(f, "Error: {}", e),
// State::Fetch(e) => write!(f, "Fetch error: {}", e),
// State::Compile(e) => write!(f, "Compile error: {}", e),
// State::Install(e) => write!(f, "Install error: {}", e),
}
}
}
impl<T> From<Result<T>> for Status {
fn from(value: Result<T>) -> Self {
match value {
Ok(_) => Status::Ok,
Err(e) => Status::Err(e),
}
}
}
pub struct Summary { pub struct Summary {
// TODO: Go back to vectors to keep order?
status: Vec<(String, Status)>, status: Vec<(String, Status)>,
} }
@ -74,7 +46,7 @@ pub fn run(opt: &Opt) -> io::Result<Summary> {
return Err(io::Error::new( return Err(io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
format!( format!(
"No package found in configuration folder. Add them in: {}", "No package found in configuration folder. Add them in: '{}'",
package_folder.display() package_folder.display()
), ),
)); ));