diff --git a/isideload/src/sideload/builder.rs b/isideload/src/sideload/builder.rs index 096601e..ba17b87 100644 --- a/isideload/src/sideload/builder.rs +++ b/isideload/src/sideload/builder.rs @@ -79,9 +79,11 @@ pub struct SideloaderBuilder { //extensions_behavior: Option, storage: Option>, machine_name: Option, + delete_app_after_install: bool, } impl SideloaderBuilder { + /// Create a new `SideloaderBuilder` with the provided Apple developer session and Apple ID email. pub fn new(developer_session: DeveloperSession, apple_email: String) -> Self { SideloaderBuilder { team_selection: None, @@ -90,6 +92,7 @@ impl SideloaderBuilder { machine_name: None, apple_email, max_certs_behavior: None, + delete_app_after_install: true, // extensions_behavior: None, } } @@ -128,6 +131,12 @@ impl SideloaderBuilder { self } + /// Set whether to delete the signed app from the temporary storage after installation. Defaults to `true`. + pub fn delete_app_after_install(mut self, delete: bool) -> Self { + self.delete_app_after_install = delete; + self + } + // pub fn extensions_behavior(mut self, behavior: ExtensionsBehavior) -> Self { // self.extensions_behavior = Some(behavior); // self @@ -145,6 +154,7 @@ impl SideloaderBuilder { .unwrap_or_else(|| Box::new(crate::util::storage::new_storage())), // self.extensions_behavior // .unwrap_or(ExtensionsBehavior::RegisterAll), + self.delete_app_after_install, ) } } diff --git a/isideload/src/sideload/sideloader.rs b/isideload/src/sideload/sideloader.rs index a1a0272..9e4f918 100644 --- a/isideload/src/sideload/sideloader.rs +++ b/isideload/src/sideload/sideloader.rs @@ -30,6 +30,7 @@ pub struct Sideloader { apple_email: String, max_certs_behavior: MaxCertsBehavior, //extensions_behavior: ExtensionsBehavior, + delete_app_after_install: bool, } impl Sideloader { @@ -44,6 +45,7 @@ impl Sideloader { machine_name: String, storage: Box, //extensions_behavior: ExtensionsBehavior, + delete_app_after_install: bool, ) -> Self { Sideloader { team_selection, @@ -53,10 +55,11 @@ impl Sideloader { apple_email, max_certs_behavior, //extensions_behavior, + delete_app_after_install, } } - /// Sign and install an app + /// Sign the app at the provided path and return the path to the signed app bundle (in a temp dir). To sign and install, see [`Self::install_app`]. pub async fn sign_app( &mut self, app_path: PathBuf, @@ -178,10 +181,12 @@ impl Sideloader { } #[cfg(feature = "install")] + /// Sign and install an app to a device. pub async fn install_app( &mut self, device_provider: &impl IdeviceProvider, app_path: PathBuf, + // this is gross but will be replaced with proper entitlement handling later increased_memory_limit: bool, ) -> Result, Report> { let device_info = IdeviceInfo::from_device(device_provider).await?; @@ -203,8 +208,15 @@ impl Sideloader { .await .context("Failed to install app on device")?; + if self.delete_app_after_install { + if let Err(e) = tokio::fs::remove_dir_all(signed_app_path).await { + tracing::warn!("Failed to remove temporary signed app file: {}", e); + }; + } + Ok(special_app) } + /// Get the developer team according to the configured team selection behavior pub async fn get_team(&mut self) -> Result { let teams = self.dev_session.list_teams().await?; diff --git a/isideload/src/util/storage.rs b/isideload/src/util/storage.rs index 9e09a5a..7b02db9 100644 --- a/isideload/src/util/storage.rs +++ b/isideload/src/util/storage.rs @@ -3,6 +3,7 @@ use std::{collections::HashMap, sync::Mutex}; use base64::prelude::*; use rootcause::prelude::*; +/// A trait for storing and retrieving sideloading related data, such as anisette state and certificates. pub trait SideloadingStorage: Send + Sync { fn store(&self, key: &str, value: &str) -> Result<(), Report>; fn retrieve(&self, key: &str) -> Result, Report>; @@ -24,6 +25,7 @@ pub trait SideloadingStorage: Send + Sync { } } +/// Factory function to create a new storage instance based on enabled features. The priority is `keyring-storage`, then `fs-storage`, and finally an in-memory storage if neither of those features are enabled. pub fn new_storage() -> impl SideloadingStorage { #[cfg(feature = "keyring-storage")] {