Skip to content

Commit

Permalink
pre-process transaction and remove menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Dec 10, 2024
1 parent 67e667d commit d053cb9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
28 changes: 26 additions & 2 deletions crates/rattler/src/install/driver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
borrow::Borrow,
collections::{HashMap, HashSet},
ffi::OsStr,
path::{Path, PathBuf},
sync::{Arc, Mutex, MutexGuard},
};
Expand Down Expand Up @@ -155,18 +156,41 @@ impl InstallDriver {
transaction: &Transaction<Old, New>,
target_prefix: &Path,
) -> Result<Option<PrePostLinkResult>, PrePostLinkError> {
let mut result = None;
if self.execute_link_scripts {
match self.run_pre_unlink_scripts(transaction, target_prefix) {
Ok(res) => {
return Ok(Some(res));
result = Some(res);
}
Err(e) => {
tracing::error!("Error running pre-unlink scripts: {:?}", e);
}
}
}

Ok(None)
// For all packages that are removed, we need to remove menuinst entries as well
for record in transaction.removed_packages().map(Borrow::borrow) {
for path in record.paths_data.paths.iter() {
if path.relative_path.starts_with("Menu")
&& path.relative_path.extension() == Some(OsStr::new("json"))
{
match rattler_menuinst::remove_menu_items(
&target_prefix.join(&path.relative_path),
target_prefix,
target_prefix,
Platform::current(),
rattler_menuinst::MenuMode::User,
) {
Ok(_) => {}
Err(e) => {
tracing::warn!("Failed to remove menu item: {}", e);
}
}
}
}
}

Ok(result)
}

/// Runs a blocking task that will execute on a separate thread. The task is
Expand Down
28 changes: 11 additions & 17 deletions crates/rattler_menuinst/src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl MacOSMenu {

let bundle_name = format!("{name}.app");
let directories = Directories::new(menu_mode, &bundle_name);
tracing::info!("Installing menu item for {bundle_name}");
tracing::info!("Editing menu item for {bundle_name}");

let refined_placeholders = placeholders.refine(&directories.location);
Self {
Expand Down Expand Up @@ -707,12 +707,16 @@ impl MacOSMenu {
}

pub fn remove(&self) -> Result<Vec<PathBuf>, MenuInstError> {
println!("Removing {}", self.directories.location.display());
tracing::info!("Removing menu item {}", self.directories.location.display());
self.maybe_register_with_launchservices(false)?;
fs_err::remove_dir_all(&self.directories.location).unwrap_or_else(|e| {
println!("Failed to remove directory: {e}. Ignoring error.");
});
Ok(vec![self.directories.location.clone()])
if self.directories.location.exists() {
fs_err::remove_dir_all(&self.directories.location).unwrap_or_else(|e| {
tracing::warn!("Failed to remove directory: {e}. Ignoring error.");
});
return Ok(vec![self.directories.location.clone()]);
} else {
return Ok(vec![]);
}
}
}

Expand All @@ -736,14 +740,4 @@ pub(crate) fn remove_menu_item(
) -> Result<Vec<PathBuf>, MenuInstError> {
let menu = MacOSMenu::new(prefix, macos_item, command, menu_mode, placeholders);

Check warning on line 741 in crates/rattler_menuinst/src/macos.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_menuinst/src/macos.rs
menu.remove()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_slugify() {
assert_eq!(slugify("Hello, World!"), "hello-world");
}
}
}
1 change: 1 addition & 0 deletions crates/rattler_menuinst/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub struct NameComplex {

pub enum Environment {
Base,
#[allow(dead_code)]
NotBase,
}

Expand Down
1 change: 1 addition & 0 deletions crates/rattler_menuinst/src/slugify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod tests {
#[test]
fn test_basic_slugify() {
assert_eq!(slugify("Hello World"), "hello-world");
assert_eq!(slugify("Hello, World!"), "hello-world");
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/rattler_menuinst/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(dead_code)]
pub fn log_output(cmd_info: &str, output: std::process::Output) {
tracing::info!("{}: status {}", cmd_info, output.status);
tracing::info!(
Expand Down

0 comments on commit d053cb9

Please sign in to comment.