pull/2067/head
Joel 8 months ago
parent a17192927d
commit e7d55ac7ed

@ -840,12 +840,6 @@ impl Update {
/// MacOS /// MacOS
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
impl Update { impl Update {
/// ### Expected structure:
/// ├── [AppName]_[version]_x64.app.tar.gz # GZ generated by tauri-bundler
/// │ └──[AppName].app # Main application
/// │ └── Contents # Application contents...
/// │ └── ...
/// └── ...
fn install_inner(&self, bytes: &[u8]) -> Result<()> { fn install_inner(&self, bytes: &[u8]) -> Result<()> {
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
@ -859,42 +853,37 @@ impl Update {
let tmp_extract_dir = tempfile::Builder::new() let tmp_extract_dir = tempfile::Builder::new()
.prefix("tauri_updated_app") .prefix("tauri_updated_app")
.tempdir()? .tempdir()?;
.into_path();
let decoder = GzDecoder::new(cursor); let decoder = GzDecoder::new(cursor);
let mut archive = tar::Archive::new(decoder); let mut archive = tar::Archive::new(decoder);
std::fs::create_dir(&tmp_extract_dir)?;
// Extract files to temporary directory // Extract files to temporary directory
for entry in archive.entries()? { for entry in archive.entries()? {
let mut entry = entry?; let mut entry = entry?;
let collected_path: PathBuf = entry.path()?.iter().skip(1).collect(); let collected_path: PathBuf = entry.path()?.iter().skip(1).collect();
let extraction_path = tmp_extract_dir.join(&collected_path); let extraction_path = tmp_extract_dir.path().join(&collected_path);
// Ensure parent directories exist
if let Some(parent) = extraction_path.parent() {
std::fs::create_dir_all(parent)?;
}
if let Err(err) = entry.unpack(&extraction_path) { if let Err(err) = entry.unpack(&extraction_path) {
// Cleanup on error // Cleanup on error
for file in &extracted_files { std::fs::remove_dir_all(tmp_extract_dir.path()).ok();
if file.is_dir() {
std::fs::remove_dir(file)?;
} else {
std::fs::remove_file(file)?;
}
}
std::fs::remove_dir_all(&tmp_extract_dir).ok();
return Err(err.into()); return Err(err.into());
} }
extracted_files.push(extraction_path); extracted_files.push(extraction_path);
} }
// Try to move the current app to backup // Try to move the current app to backup
let move_result = std::fs::rename(&self.extract_path, tmp_backup_dir.path()); let move_result = std::fs::rename(&self.extract_path, tmp_backup_dir.path().join("current_app"));
let need_authorization = if let Err(err) = move_result { let need_authorization = if let Err(err) = move_result {
if err.kind() == std::io::ErrorKind::PermissionDenied { if err.kind() == std::io::ErrorKind::PermissionDenied {
true true
} else { } else {
std::fs::remove_dir_all(&tmp_extract_dir).ok(); std::fs::remove_dir_all(tmp_extract_dir.path()).ok();
return Err(err.into()); return Err(err.into());
} }
} else { } else {
@ -904,10 +893,9 @@ impl Update {
if need_authorization { if need_authorization {
// Use AppleScript to perform moves with admin privileges // Use AppleScript to perform moves with admin privileges
let script = format!( let script = format!(
"do shell script \"mv -f '{src}' '{backup}' && mv -f '{new}' '{src}'\" with administrator privileges", "do shell script \"rm -rf '{src}' && mv -f '{new}' '{src}'\" with administrator privileges",
src = self.extract_path.display(), src = self.extract_path.display(),
backup = tmp_backup_dir.path().display(), new = tmp_extract_dir.path().display()
new = tmp_extract_dir.display()
); );
let mut osascript = std::process::Command::new("osascript"); let mut osascript = std::process::Command::new("osascript");
@ -915,15 +903,19 @@ impl Update {
let status = osascript.status()?; let status = osascript.status()?;
if !status.success() { if !status.success() {
std::fs::remove_dir_all(&tmp_extract_dir).ok(); std::fs::remove_dir_all(tmp_extract_dir.path()).ok();
return Err(Error::Io(std::io::Error::new( return Err(Error::Io(std::io::Error::new(
std::io::ErrorKind::PermissionDenied, std::io::ErrorKind::PermissionDenied,
"Failed to move the new app into place", "Failed to move the new app into place",
))); )));
} }
} else { } else {
// Move the new app to the target path if we didn't need admin rights // Remove existing directory if it exists
std::fs::rename(&tmp_extract_dir, &self.extract_path)?; if self.extract_path.exists() {
std::fs::remove_dir_all(&self.extract_path)?;
}
// Move the new app to the target path
std::fs::rename(tmp_extract_dir.path(), &self.extract_path)?;
} }
let _ = std::process::Command::new("touch") let _ = std::process::Command::new("touch")

Loading…
Cancel
Save