fix: reduced app size by a good margin
This commit is contained in:
@@ -4,6 +4,9 @@ edition.workspace = true
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[lib]
|
||||
crate-type = ["dylib"]
|
||||
|
||||
[dependencies]
|
||||
uuid = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -14,14 +14,18 @@ pub fn install_launcher(executable: &Path, home_dir: &Path) -> EngineResult<Path
|
||||
let bin_dir = home_dir.join(".local/bin");
|
||||
std::fs::create_dir_all(&bin_dir)?;
|
||||
let target = bin_dir.join(if cfg!(windows) {
|
||||
"bds-cli.exe"
|
||||
"bds-cli.cmd"
|
||||
} else {
|
||||
"bds-cli"
|
||||
});
|
||||
let source = executable.canonicalize()?;
|
||||
let launcher = launcher_contents(&source);
|
||||
#[cfg(unix)]
|
||||
if target.is_symlink() && target.canonicalize().ok().as_ref() == Some(&source) {
|
||||
std::fs::remove_file(&target)?;
|
||||
}
|
||||
if target.exists() {
|
||||
let existing = target.canonicalize().ok();
|
||||
let source = executable.canonicalize()?;
|
||||
if existing.as_ref() != Some(&source) {
|
||||
if std::fs::read(&target).ok().as_deref() != Some(launcher.as_bytes()) {
|
||||
return Err(EngineError::Conflict(format!(
|
||||
"refusing to overwrite existing launcher at {}",
|
||||
target.display()
|
||||
@@ -30,13 +34,29 @@ pub fn install_launcher(executable: &Path, home_dir: &Path) -> EngineResult<Path
|
||||
return Ok(target);
|
||||
}
|
||||
|
||||
std::fs::write(&target, launcher)?;
|
||||
#[cfg(unix)]
|
||||
std::os::unix::fs::symlink(executable.canonicalize()?, &target)?;
|
||||
#[cfg(windows)]
|
||||
std::fs::copy(executable, &target)?;
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt as _;
|
||||
let mut permissions = std::fs::metadata(&target)?.permissions();
|
||||
permissions.set_mode(0o755);
|
||||
std::fs::set_permissions(&target, permissions)?;
|
||||
}
|
||||
Ok(target)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn launcher_contents(executable: &Path) -> String {
|
||||
let quoted = executable.to_string_lossy().replace('\'', "'\"'\"'");
|
||||
format!("#!/bin/sh\nexec '{quoted}' \"$@\"\n")
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn launcher_contents(executable: &Path) -> String {
|
||||
let escaped = executable.to_string_lossy().replace('%', "%%");
|
||||
format!("@echo off\r\n\"{escaped}\" %*\r\n")
|
||||
}
|
||||
|
||||
/// Resolve the CLI shipped beside the desktop executable and install it.
|
||||
pub fn install_packaged_launcher(home_dir: &Path) -> EngineResult<PathBuf> {
|
||||
let app = std::env::current_exe()?;
|
||||
@@ -59,10 +79,9 @@ mod tests {
|
||||
std::fs::write(&executable, b"binary").unwrap();
|
||||
let home = root.path().join("home");
|
||||
let target = install_launcher(&executable, &home).unwrap();
|
||||
assert_eq!(
|
||||
target.canonicalize().unwrap(),
|
||||
executable.canonicalize().unwrap()
|
||||
);
|
||||
assert!(!target.is_symlink());
|
||||
let launcher = std::fs::read_to_string(&target).unwrap();
|
||||
assert!(launcher.contains(executable.canonicalize().unwrap().to_str().unwrap()));
|
||||
assert_eq!(install_launcher(&executable, &home).unwrap(), target);
|
||||
|
||||
std::fs::remove_file(&target).unwrap();
|
||||
@@ -70,4 +89,24 @@ mod tests {
|
||||
assert!(install_launcher(&executable, &home).is_err());
|
||||
assert_eq!(std::fs::read(&target).unwrap(), b"mine");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn replaces_the_previous_installer_symlink_with_a_forwarding_launcher() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let executable = root.path().join("packaged-bds-cli");
|
||||
std::fs::write(&executable, b"binary").unwrap();
|
||||
let home = root.path().join("home");
|
||||
let target = home.join(".local/bin/bds-cli");
|
||||
std::fs::create_dir_all(target.parent().unwrap()).unwrap();
|
||||
std::os::unix::fs::symlink(&executable, &target).unwrap();
|
||||
|
||||
assert_eq!(install_launcher(&executable, &home).unwrap(), target);
|
||||
assert!(!target.is_symlink());
|
||||
assert!(
|
||||
std::fs::read_to_string(target)
|
||||
.unwrap()
|
||||
.starts_with("#!/bin/sh")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1599,7 +1599,7 @@ mod tests {
|
||||
let engine = GitEngine::with_executable_and_timeouts(
|
||||
dir.path(),
|
||||
executable,
|
||||
Duration::from_secs(1),
|
||||
Duration::from_secs(5),
|
||||
Duration::from_secs(1),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user