mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
fix: apply is trying to restart the wrong binary after update
This commit is contained in:
@@ -30,10 +30,15 @@ pub fn apply<'a>(
|
||||
let package = package.cloned().map_or_else(|| auto_locate_package(&app, &root_path), Ok);
|
||||
match package {
|
||||
Ok(package) => {
|
||||
info!("Getting ready to apply package: {}", package.to_string_lossy());
|
||||
info!("Getting ready to apply package to {} ver {}: {}", app.id, app.version, package.to_string_lossy());
|
||||
match apply_package_impl(&root_path, &app, &package, runhooks) {
|
||||
Ok(_) => {
|
||||
info!("Package applied successfully.");
|
||||
Ok(applied_app) => {
|
||||
info!("Package version {} applied successfully.", applied_app.version);
|
||||
// if successful, we want to restart the new version of the app, which could have different metadata
|
||||
if restart {
|
||||
shared::start_package(&applied_app, &root_path, exe_args, Some("VELOPACK_RESTART"))?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Error applying package: {}", e);
|
||||
@@ -45,12 +50,12 @@ pub fn apply<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: if the package fails to start, or fails hooks, we could roll back the install
|
||||
// an error occurred if we're here, but we still want to restart the old version of the app if it was requested
|
||||
if restart {
|
||||
shared::start_package(&app, &root_path, exe_args, Some("VELOPACK_RESTART"))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
bail!("Apply failed, see logs for details.");
|
||||
}
|
||||
|
||||
fn auto_locate_package(app: &Manifest, _root_path: &PathBuf) -> Result<PathBuf> {
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::shared::{
|
||||
use anyhow::{bail, Result};
|
||||
use std::{fs, path::PathBuf, process::Command};
|
||||
|
||||
pub fn apply_package_impl<'a>(root_path: &PathBuf, _app: &Manifest, pkg: &PathBuf, _runhooks: bool) -> Result<()> {
|
||||
pub fn apply_package_impl<'a>(root_path: &PathBuf, _app: &Manifest, pkg: &PathBuf, _runhooks: bool) -> Result<Manifest> {
|
||||
// on linux, the current "dir" is actually an AppImage file which we need to replace.
|
||||
info!("Loading bundle from {}", pkg.to_string_lossy());
|
||||
let bundle = bundle::load_bundle_from_file(pkg)?;
|
||||
@@ -56,5 +56,6 @@ pub fn apply_package_impl<'a>(root_path: &PathBuf, _app: &Manifest, pkg: &PathBu
|
||||
})();
|
||||
let _ = fs::remove_file(&script_path);
|
||||
let _ = fs::remove_file(&temp_path);
|
||||
action
|
||||
action?;
|
||||
Ok(manifest)
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ use crate::shared::{
|
||||
use anyhow::{bail, Result};
|
||||
use std::{fs, path::PathBuf, process::Command};
|
||||
|
||||
pub fn apply_package_impl<'a>(root_path: &PathBuf, app: &Manifest, pkg: &PathBuf, _runhooks: bool) -> Result<()> {
|
||||
pub fn apply_package_impl<'a>(root_path: &PathBuf, app: &Manifest, pkg: &PathBuf, _runhooks: bool) -> Result<Manifest> {
|
||||
let tmp_path_new = format!("/tmp/velopack/{}/{}", app.id, shared::random_string(8));
|
||||
let tmp_path_old = format!("/tmp/velopack/{}/{}", app.id, shared::random_string(8));
|
||||
let bundle = bundle::load_bundle_from_file(pkg)?;
|
||||
let manifest = bundle.read_manifest()?;
|
||||
|
||||
let action: Result<()> = (|| {
|
||||
// 1. extract the bundle to a temp dir
|
||||
let bundle = bundle::load_bundle_from_file(pkg)?;
|
||||
let manifest = bundle.read_manifest()?;
|
||||
fs::create_dir_all(&tmp_path_new)?;
|
||||
info!("Extracting bundle to {}", &tmp_path_new);
|
||||
bundle.extract_lib_contents_to_path(&tmp_path_new, |_| {})?;
|
||||
@@ -59,5 +59,6 @@ pub fn apply_package_impl<'a>(root_path: &PathBuf, app: &Manifest, pkg: &PathBuf
|
||||
})();
|
||||
let _ = fs::remove_dir_all(&tmp_path_new);
|
||||
let _ = fs::remove_dir_all(&tmp_path_old);
|
||||
action
|
||||
action?;
|
||||
Ok(manifest)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
use anyhow::{bail, Result};
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub fn apply_package_impl<'a>(root_path: &PathBuf, app: &Manifest, package: &PathBuf, runhooks: bool) -> Result<()> {
|
||||
pub fn apply_package_impl<'a>(root_path: &PathBuf, app: &Manifest, package: &PathBuf, runhooks: bool) -> Result<Manifest> {
|
||||
let bundle = bundle::load_bundle_from_file(&package)?;
|
||||
let manifest = bundle.read_manifest()?;
|
||||
|
||||
@@ -91,5 +91,6 @@ pub fn apply_package_impl<'a>(root_path: &PathBuf, app: &Manifest, package: &Pat
|
||||
|
||||
let _ = remove_dir_all::remove_dir_all(&temp_path_new);
|
||||
let _ = remove_dir_all::remove_dir_all(&temp_path_old);
|
||||
action
|
||||
action?;
|
||||
Ok(manifest)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user