OSX now compiled

This commit is contained in:
Caelan Sayler
2024-09-30 08:56:52 -06:00
committed by Caelan
parent 2cdcbf1c22
commit 6221a6cc9e
2 changed files with 18 additions and 25 deletions

View File

@@ -4,30 +4,25 @@ use crate::shared::{
};
use anyhow::{bail, Result};
use std::{fs, path::PathBuf, process::Command};
use velopack::locator::VelopackLocator;
use velopack::{bundle, locator::VelopackLocator};
pub fn apply_package_impl<'a>(locator: &VelopackLocator, pkg: &PathBuf, _runhooks: bool) -> Result<VelopackLocator> {
#[allow(deprecated)]
let mut cache_dir = std::env::home_dir().expect("Could not locate user home directory via $HOME or /etc/passwd");
cache_dir.push("Library");
cache_dir.push("Caches");
cache_dir.push("velopack");
cache_dir.push(&app.id);
let tmp_path_new = cache_dir.join(shared::random_string(8) + ".tmp").to_string_lossy().to_string();
let tmp_path_old = cache_dir.join(shared::random_string(8) + ".tmp").to_string_lossy().to_string();
let bundle = bundle::load_bundle_from_file(pkg)?;
let root_path = locator.get_root_dir();
let tmp_path_new = locator.get_temp_dir_rand16();
let tmp_path_old = locator.get_temp_dir_rand16();
let mut bundle = bundle::load_bundle_from_file(pkg)?;
let manifest = bundle.read_manifest()?;
let new_locator = locator.clone_self_with_new_manifest(&manifest);
let action: Result<()> = (|| {
// 1. extract the bundle to a temp dir
fs::create_dir_all(&tmp_path_new)?;
info!("Extracting bundle to {}", &tmp_path_new);
info!("Extracting bundle to {:?}", &tmp_path_new);
bundle.extract_lib_contents_to_path(&tmp_path_new, |_| {})?;
// 2. attempt to replace the current bundle with the new one
let result: Result<()> = (|| {
info!("Replacing bundle at {}", &root_path.to_string_lossy());
info!("Replacing bundle at {:?}", &root_path);
fs::rename(&root_path, &tmp_path_old)?;
fs::rename(&tmp_path_new, &root_path)?;
Ok(())
@@ -35,21 +30,21 @@ pub fn apply_package_impl<'a>(locator: &VelopackLocator, pkg: &PathBuf, _runhook
match result {
Ok(()) => {
info!("Bundle extracted successfully to {}", &root_path.to_string_lossy());
info!("Bundle extracted successfully to {:?}", &root_path);
Ok(())
}
Err(e) => {
// 3. if fails for permission error, try again escallated via osascript
// 3. if fails for permission error, try again escalated via osascript
if shared::is_error_permission_denied(&e) {
error!("A permissions error occurred ({}), will attempt to elevate permissions and try again...", e);
dialogs::ask_user_to_elevate(&manifest)?;
dialogs::ask_user_to_elevate(&manifest.title, &manifest.version.to_string())?;
let script = format!(
"do shell script \"mv -f '{}' '{}' && mv -f '{}' '{}' && rm -rf '{}'\" with administrator privileges",
&root_path.to_string_lossy(),
&tmp_path_old,
&tmp_path_new,
&tmp_path_old.to_string_lossy(),
&tmp_path_new.to_string_lossy(),
&root_path.to_string_lossy(),
&tmp_path_old
&tmp_path_old.to_string_lossy()
);
info!("Running elevated process via osascript: {}", script);
let output = Command::new("osascript").arg("-e").arg(&script).status()?;
@@ -68,5 +63,5 @@ pub fn apply_package_impl<'a>(locator: &VelopackLocator, pkg: &PathBuf, _runhook
let _ = fs::remove_dir_all(&tmp_path_new);
let _ = fs::remove_dir_all(&tmp_path_old);
action?;
Ok(manifest)
Ok(new_locator)
}

View File

@@ -149,11 +149,9 @@ impl VelopackLocator {
self.paths.PackagesDir.join("VelopackTemp")
}
/// Creates a new temporary directory inside get_temp_dir_root() with a random 16-character suffix.
pub fn get_temp_dir_rand16(&self) -> Result<PathBuf, Error> {
let p = self.get_temp_dir_root().join("tmp_".to_string() + &util::random_string(16));
std::fs::create_dir_all(&p)?;
Ok(p)
/// Get the name of a new temporary directory inside get_temp_dir_root() with a random 16-character suffix.
pub fn get_temp_dir_rand16(&self) -> PathBuf {
self.get_temp_dir_root().join("tmp_".to_string() + &util::random_string(16))
}
/// Returns the path to the current app temporary directory as a string.