From 9acd9f69f3237583362780fda7fdc122edea02b6 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 8 Aug 2018 20:29:59 +1000 Subject: [PATCH] Clean up wasted allocations in shortcut generation --- src/native/mod.rs | 4 ++-- src/rest.rs | 2 +- src/tasks/install_global_shortcut.rs | 10 +++++++--- src/tasks/uninstall_global_shortcut.rs | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/native/mod.rs b/src/native/mod.rs index acbd117..996fe22 100644 --- a/src/native/mod.rs +++ b/src/native/mod.rs @@ -63,7 +63,7 @@ mod natives { } /// Cleans up the installer - pub fn burn_on_exit(path: PathBuf) { + pub fn burn_on_exit(path: &PathBuf) { // Need a cmd workaround here. let tool = path.join("maintenancetool.exe"); let tool = tool @@ -108,7 +108,7 @@ mod natives { } /// Cleans up the installer - pub fn burn_on_exit(path: PathBuf) { + pub fn burn_on_exit(path: &PathBuf) { // Thank god for *nix platforms if let Err(e) = remove_file(path.join("/maintenancetool")) { // No regular logging now. diff --git a/src/rest.rs b/src/rest.rs index 4d8a1bb..8c6bb88 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -209,7 +209,7 @@ impl Service for WebService { if framework.burn_after_exit { let path = framework .install_path - .clone() + .as_ref() .log_expect("No install path when one should have existed?"); println!("Base path: {:?}", path); diff --git a/src/tasks/install_global_shortcut.rs b/src/tasks/install_global_shortcut.rs index 8bce2a4..eeb618e 100644 --- a/src/tasks/install_global_shortcut.rs +++ b/src/tasks/install_global_shortcut.rs @@ -21,7 +21,7 @@ impl Task for InstallGlobalShortcutsTask { context: &mut InstallerFramework, messenger: &Fn(&str, f64), ) -> Result { - messenger(&format!("Generating global shortcut..."), 0.0); + messenger("Generating global shortcut...", 0.0); let path = context .install_path @@ -44,7 +44,7 @@ impl Task for InstallGlobalShortcutsTask { .to_str() .log_expect("Unable to build shortcut metadata (tool)"); - context.database.shortcuts.push(create_shortcut( + let shortcut_file = create_shortcut( &format!("{} maintenance tool", context.base_attributes.name), &format!( "Launch the {} maintenance tool to update, modify and uninstall the application.", @@ -54,7 +54,11 @@ impl Task for InstallGlobalShortcutsTask { // TODO: Send by list "", &starting_dir, - )?); + )?; + + if !shortcut_file.is_empty() { + context.database.shortcuts.push(shortcut_file); + } Ok(TaskParamType::None) } diff --git a/src/tasks/uninstall_global_shortcut.rs b/src/tasks/uninstall_global_shortcut.rs index 828dff0..fc7d901 100644 --- a/src/tasks/uninstall_global_shortcut.rs +++ b/src/tasks/uninstall_global_shortcut.rs @@ -21,7 +21,7 @@ impl Task for UninstallGlobalShortcutsTask { ) -> Result { assert_eq!(input.len(), 0); - messenger(&format!("Uninstalling global shortcut..."), 0.0); + messenger("Uninstalling global shortcut...", 0.0); while let Some(file) = context.database.shortcuts.pop() { info!("Deleting shortcut {:?}", file);