mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-15 06:52:23 +00:00
craft-update: log an install failure picked up at exit and clear the finished job
This commit is contained in:
1 parent
f5f45b090c
commit
0e856027c5
1 file changed
+22
-3
@@ -404,11 +404,17 @@ impl Updater {
|
||||
pub fn start_pending_update(&mut self) {
|
||||
// An installation that finished since the last `tick`.
|
||||
if let Some((rx, release)) = &self.install
|
||||
&& let Ok(Ok(restart)) = rx.try_recv()
|
||||
&& let Ok(outcome) = rx.try_recv()
|
||||
{
|
||||
self.restart = Some((restart, release.clone()));
|
||||
match outcome {
|
||||
Ok(restart) => {
|
||||
self.restart = Some((restart, release.clone()));
|
||||
self.installed = true;
|
||||
}
|
||||
Err(Failure::Installer(e)) => log::warn!("{} self-update failed: {e}", self.app.name),
|
||||
Err(Failure::Updater(note)) => log::warn!("{} self-update failed: {}", self.app.name, note.translated(english)),
|
||||
}
|
||||
self.install = None;
|
||||
self.installed = true;
|
||||
}
|
||||
if let Some((restart, _)) = self.restart.take()
|
||||
&& let Err(e) = restart.start()
|
||||
@@ -899,6 +905,19 @@ mod tests {
|
||||
assert_eq!(starts.load(Ordering::SeqCst), 1, "the helper starts once");
|
||||
}
|
||||
|
||||
/// A failed installation picked up at exit leaves nothing installed and nothing waiting.
|
||||
#[test]
|
||||
fn a_failed_install_picked_up_at_exit_leaves_nothing_waiting() {
|
||||
let mut u = updater(Ok(None));
|
||||
let (tx, rx) = channel::<Result<Restart, Failure>>();
|
||||
u.install = Some((rx, newer()));
|
||||
assert!(tx.send(Err("couldn't download the update".into())).is_ok());
|
||||
u.start_pending_update();
|
||||
assert!(u.install.is_none(), "the finished job is cleared");
|
||||
assert!(!u.installed);
|
||||
assert!(u.restart.is_none());
|
||||
}
|
||||
|
||||
/// A helper started at [`Action::Close`] does not start again when the updater is dropped.
|
||||
#[test]
|
||||
fn a_helper_started_at_close_does_not_start_again_on_drop() {
|
||||
|
||||
Reference in new issue
Block a user