mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
cli: implement better self-updating
- Start separating a "standalone" CLI. This is a little awkward with clap- derive, but I got it working. Detection of whether the CLI _is_ standalone is still todo. - Remove the old ad-hoc update code for code-server, and use the update service instead. - Fix some of the "permission denied" errors people got while updating before. We need to rename the old running binary, not just overwrite it.
This commit is contained in:
@@ -4,12 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
use crate::constants::{CONTROL_PORT, PROTOCOL_VERSION, VSCODE_CLI_VERSION};
|
||||
use crate::log;
|
||||
use crate::self_update::SelfUpdate;
|
||||
use crate::state::LauncherPaths;
|
||||
use crate::update::Update;
|
||||
use crate::update_service::Platform;
|
||||
use crate::update_service::{Platform, UpdateService};
|
||||
use crate::util::errors::{
|
||||
wrap, AnyError, MismatchedLaunchModeError, NoAttachedServerError, ServerWriteError,
|
||||
};
|
||||
use crate::util::io::SilentCopyProgress;
|
||||
use crate::util::sync::{new_barrier, Barrier};
|
||||
use opentelemetry::trace::SpanKind;
|
||||
use opentelemetry::KeyValue;
|
||||
@@ -617,13 +618,10 @@ async fn handle_update(
|
||||
ctx: &HandlerContext,
|
||||
params: &UpdateParams,
|
||||
) -> Result<UpdateResult, AnyError> {
|
||||
let updater = Update::new();
|
||||
let latest_release = updater.get_latest_release().await?;
|
||||
|
||||
let up_to_date = match VSCODE_CLI_VERSION {
|
||||
Some(v) => v == latest_release.version,
|
||||
None => true,
|
||||
};
|
||||
let update_service = UpdateService::new(ctx.log.clone(), reqwest::Client::new());
|
||||
let updater = SelfUpdate::new(&update_service)?;
|
||||
let latest_release = updater.get_current_release().await?;
|
||||
let up_to_date = updater.is_up_to_date_with(&latest_release);
|
||||
|
||||
if !params.do_update || up_to_date {
|
||||
return Ok(UpdateResult {
|
||||
@@ -632,12 +630,10 @@ async fn handle_update(
|
||||
});
|
||||
}
|
||||
|
||||
info!(ctx.log, "Updating CLI from {}", latest_release.version);
|
||||
|
||||
let current_exe = std::env::current_exe().map_err(|e| wrap(e, "could not get current exe"))?;
|
||||
info!(ctx.log, "Updating CLI to {}", latest_release);
|
||||
|
||||
updater
|
||||
.switch_to_release(&latest_release, ¤t_exe)
|
||||
.do_update(&latest_release, SilentCopyProgress())
|
||||
.await?;
|
||||
|
||||
Ok(UpdateResult {
|
||||
|
||||
Reference in New Issue
Block a user