Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/AdastralGroup/beans-rs i…
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
ktwrd committed Jun 9, 2024
2 parents bca1e6e + 5470b89 commit 9c2c79e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 32 deletions.
Binary file removed Binaries/7z.dll
Binary file not shown.
Binary file removed Binaries/7z.so
Binary file not shown.
Binary file removed Binaries/c7zip.dll
Binary file not shown.
Binary file removed Binaries/libc7zip.so
Binary file not shown.
22 changes: 22 additions & 0 deletions src/butler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,26 @@ pub fn patch(
Ok(w)
}
}
}

pub fn fetch_7z_libs() -> Result<ExitStatus, BeansError> {
println!("[butler::fetch_7z_libs] fetching 7z libraries");
match std::process::Command::new(&depends::get_butler_location())
.arg("fetch-7z-libs")
.spawn() {
Err(e) => {
let xe = BeansError::IO {
error: e,
backtrace: Backtrace::capture()
};

sentry::capture_error(&xe);
Err(xe)
},
Ok(mut v) => {
let w = v.wait()?;
debug!("Exited with {:#?}", w);
Ok(w)
}
}
}
30 changes: 6 additions & 24 deletions src/depends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
use std::os::unix::fs::PermissionsExt;
#[cfg(target_os = "windows")]
use std::backtrace::Backtrace;
use crate::{BeansError, BUTLER_BINARY, BUTLER_LIB_1, BUTLER_LIB_2, helper};
use crate::{BeansError, BUTLER_BINARY, helper, butler};
use log::{debug, error};

/// try and write aria2c and butler if it doesn't exist
/// paths that are used will be fetched from binary_locations()
pub fn try_write_deps()
{
safe_write_file(get_butler_location().as_str(), &**BUTLER_BINARY);
safe_write_file(get_butler_1_location().as_str(), &**BUTLER_LIB_1);
safe_write_file(get_butler_2_location().as_str(), &**BUTLER_LIB_2);
#[cfg(not(target_os = "windows"))]
if helper::file_exists(get_butler_location()) {
let p = std::fs::Permissions::from_mode(0744 as u32);
Expand All @@ -22,6 +20,11 @@ pub fn try_write_deps()
}
debug!("[depends::try_write_deps] set perms on {}", get_butler_location());
}

if let Err(e) = butler::fetch_7z_libs() {
error!("[depends::try_write_deps] Failed to fetch 7z libaries");
error!("[depends::try_write_deps] {:#?}", e);
}
}
fn safe_write_file(location: &str, data: &[u8]) {
if !helper::file_exists(location.to_string())
Expand Down Expand Up @@ -97,8 +100,6 @@ pub async fn try_install_vcredist() -> Result<(), BeansError>

pub fn butler_exists() -> bool {
helper::file_exists(get_butler_location())
&& helper::file_exists(get_butler_1_location())
&& helper::file_exists(get_butler_2_location())
}

pub fn get_butler_location() -> String
Expand All @@ -107,16 +108,6 @@ pub fn get_butler_location() -> String
path.push_str(BUTLER_LOCATION);
path
}
pub fn get_butler_1_location() -> String {
let mut path = get_tmp_dir();
path.push_str(BUTLER_1);
path
}
pub fn get_butler_2_location() -> String {
let mut path = get_tmp_dir();
path.push_str(BUTLER_2);
path
}
fn get_tmp_dir() -> String {
let path = helper::get_tmp_dir();
helper::format_directory_path(path)
Expand All @@ -126,12 +117,3 @@ fn get_tmp_dir() -> String {
const BUTLER_LOCATION: &str = "butler.exe";
#[cfg(not(target_os = "windows"))]
const BUTLER_LOCATION: &str = "butler";

#[cfg(target_os = "windows")]
const BUTLER_1: &str = "7z.dll";
#[cfg(not(target_os = "windows"))]
const BUTLER_1: &str = "7z.so";
#[cfg(target_os = "windows")]
const BUTLER_2: &str = "c7zip.dll";
#[cfg(not(target_os = "windows"))]
const BUTLER_2: &str = "libc7zip.so";
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,3 @@ pub const STAGING_DIR: &str = "\\butler-staging";
flate!(pub static BUTLER_BINARY: [u8] from "Binaries/butler.exe");
#[cfg(not(target_os = "windows"))]
flate!(pub static BUTLER_BINARY: [u8] from "Binaries/butler");
#[cfg(target_os = "windows")]
flate!(pub static BUTLER_LIB_1: [u8] from "Binaries/7z.dll");
#[cfg(not(target_os = "windows"))]
flate!(pub static BUTLER_LIB_1: [u8] from "Binaries/7z.so");
#[cfg(target_os = "windows")]
flate!(pub static BUTLER_LIB_2: [u8] from "Binaries/c7zip.dll");
#[cfg(not(target_os = "windows"))]
flate!(pub static BUTLER_LIB_2: [u8] from "Binaries/libc7zip.so");

0 comments on commit 9c2c79e

Please sign in to comment.