From 76ade2fc2d1dc31c2bb40f84b1ace2fb15927251 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 24 Feb 2017 01:06:35 +0100 Subject: [PATCH] Sane updater (#4658) * Make updater avoid downloading earlier versions. * Disable if files can't be moved. --- updater/src/updater.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/updater/src/updater.rs b/updater/src/updater.rs index 9c86099b8..31c3106bd 100644 --- a/updater/src/updater.rs +++ b/updater/src/updater.rs @@ -79,6 +79,8 @@ struct UpdaterState { installed: Option, capability: CapState, + + disabled: bool, } /// Service for checking for updates and determining whether we can achieve consensus. @@ -204,16 +206,16 @@ impl Updater { } fn fetch_done(&self, result: Result) { - (|| -> Result<(), String> { + (|| -> Result<(), (String, bool)> { let auto = { let mut s = self.state.lock(); let fetched = s.fetching.take().unwrap(); - let b = result.map_err(|e| format!("Unable to fetch update ({}): {:?}", fetched.version, e))?; + let b = result.map_err(|e| (format!("Unable to fetch update ({}): {:?}", fetched.version, e), false))?; info!(target: "updater", "Fetched latest version ({}) OK to {}", fetched.version, b.display()); let dest = self.updates_path(&Self::update_file_name(&fetched.version)); - fs::create_dir_all(dest.parent().expect("at least one thing pushed; qed")).map_err(|e| format!("Unable to create updates path: {:?}", e))?; - fs::copy(&b, &dest).map_err(|e| format!("Unable to copy update: {:?}", e))?; - restrict_permissions_owner(&dest, false, true).map_err(|e| format!("Unable to update permissions: {}", e))?; + fs::create_dir_all(dest.parent().expect("at least one thing pushed; qed")).map_err(|e| (format!("Unable to create updates path: {:?}", e), true))?; + fs::copy(&b, &dest).map_err(|e| (format!("Unable to copy update: {:?}", e), true))?; + restrict_permissions_owner(&dest, false, true).map_err(|e| (format!("Unable to update permissions: {}", e), true))?; info!(target: "updater", "Installed updated binary to {}", dest.display()); let auto = match self.update_policy.filter { UpdateFilter::All => true, @@ -228,7 +230,7 @@ impl Updater { self.execute_upgrade(); } Ok(()) - })().unwrap_or_else(|e| warn!("{}", e)); + })().unwrap_or_else(|(e, fatal)| { self.state.lock().disabled = fatal; warn!("{}", e); }); } fn poll(&self) { @@ -266,9 +268,10 @@ impl Updater { } ); let mut s = self.state.lock(); + let running_later = latest.track.version.version < self.version_info().version; let running_latest = latest.track.version.hash == self.version_info().hash; let already_have_latest = s.installed.as_ref().or(s.ready.as_ref()).map_or(false, |t| *t == latest.track); - if self.update_policy.enable_downloading && !running_latest && !already_have_latest { + if self.update_policy.enable_downloading && !running_later && !running_latest && !already_have_latest { if let Some(b) = latest.track.binary { if s.fetching.is_none() { info!(target: "updater", "Attempting to get parity binary {}", b);