Remove bindetect and chmod 755 all files we extract on macos

This commit is contained in:
Caelan Sayler
2024-11-07 20:42:28 +00:00
committed by Caelan
parent cd7761bd3c
commit e924fb4d69
4 changed files with 5 additions and 54 deletions

View File

@@ -233,7 +233,7 @@ namespace Velopack
}
EnsureInstalled();
using var _mut = await AcquireUpdateLock();
using var _mut = await AcquireUpdateLock().ConfigureAwait(false);
var appTempDir = Locator.AppTempDir!;

View File

@@ -1,46 +0,0 @@
#![allow(dead_code)]
use std::fs::File;
use std::io::{self, Read};
use std::path::Path;
// https://developer.apple.com/documentation/kernel/fat_header/1558632-magic/
// https://opensource.apple.com/source/file/file-80.40.2/file/magic/Magdir/cafebabe.auto.html
#[derive(Debug)]
#[allow(non_camel_case_types)]
enum MagicMachO {
MH_MAGIC,
MH_CIGAM,
MH_MAGIC_64,
MH_CIGAM_64,
FAT_MAGIC,
FAT_CIGAM,
}
impl MagicMachO {
fn from_u32(value: u32) -> Option<Self> {
match value {
0xfeedface => Some(MagicMachO::MH_MAGIC),
0xcefaedfe => Some(MagicMachO::MH_CIGAM),
0xfeedfacf => Some(MagicMachO::MH_MAGIC_64),
0xcffaedfe => Some(MagicMachO::MH_CIGAM_64),
0xcafebabe => Some(MagicMachO::FAT_MAGIC),
0xbebafeca => Some(MagicMachO::FAT_CIGAM),
_ => None,
}
}
}
pub fn is_macho_image<P: AsRef<Path>>(file_path: P) -> io::Result<bool> {
let file_path = file_path.as_ref();
let mut file = File::open(file_path)?;
let mut buffer = [0; 4];
if file.metadata()?.len() < 256 {
return Ok(false);
}
file.read_exact(&mut buffer)?;
let magic = u32::from_be_bytes(buffer);
Ok(MagicMachO::from_u32(magic).is_some())
}

View File

@@ -298,14 +298,12 @@ impl BundleZip<'_> {
self.extract_zip_idx_to_path(i, &file_path_on_disk)?;
// on macos, we need to chmod +x the executable files
// for now, we just chmod 755 every file we extract. this is not great, ideally we
// will preserve the mode as it was when packaging. This will come in a future release.
#[cfg(target_os = "macos")]
{
if let Ok(true) = super::bindetect::is_macho_image(&file_path_on_disk) {
if let Err(e) = std::fs::set_permissions(&file_path_on_disk, std::fs::Permissions::from_mode(0o755)) {
warn!("Failed to set executable permissions on '{}': {}", file_path_on_disk.to_string_lossy(), e);
} else {
info!(" {} Set executable permissions on '{}'", i, file_path_on_disk.to_string_lossy());
}
if let Err(e) = std::fs::set_permissions(&file_path_on_disk, std::fs::Permissions::from_mode(0o755)) {
warn!("Failed to set mode 755 on '{}': {}", file_path_on_disk.to_string_lossy(), e);
}
}

View File

@@ -81,7 +81,6 @@
mod app;
mod manager;
mod util;
mod bindetect;
/// Utility functions for loading and working with Velopack bundles and manifests.
pub mod bundle;