From c36b3b14ab60ca1f66df1991b6d4315cd61c3b1d Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Wed, 12 Apr 2023 11:25:12 -0400 Subject: [PATCH] Use `try_for_each_with` in `Installer::install` to avoid using a mutex on the Sender. --- src/creator/mod.rs | 4 +--- src/installer/mod.rs | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/creator/mod.rs b/src/creator/mod.rs index c6423bd..4c7a5be 100644 --- a/src/creator/mod.rs +++ b/src/creator/mod.rs @@ -1,8 +1,6 @@ -use hpk_package::deku::DekuError; - use { crate::{Item, ItemError, Package, Plist, Specs}, - hpk_package::{tar, Entry}, + hpk_package::{deku::DekuError, tar, Entry}, rayon::prelude::{IntoParallelRefIterator, ParallelIterator}, std::{ borrow::BorrowMut, diff --git a/src/installer/mod.rs b/src/installer/mod.rs index 1c26d18..7d40a82 100644 --- a/src/installer/mod.rs +++ b/src/installer/mod.rs @@ -100,9 +100,9 @@ impl Installer { pr_node.write(writer)?; let path = &self.path; let package = &self.package; - let sender = Mutex::new(sender); let hooks = Mutex::new(hooks); - archive.nodes.par_iter().try_for_each(|node| { + let s = sender.clone(); + archive.nodes.par_iter().try_for_each_with(s, |sender, node| { let mut path = path.clone(); let fpath = node.header.file_path()?; if let Some(s) = node.header.prefix() { @@ -153,7 +153,7 @@ impl Installer { } } let msg = extract_entry(entry, node, path)?; - sender.lock().unwrap().send(msg)?; + sender.send(msg)?; Ok::<(), InstallError>(()) })?; Ok(hooks.into_inner()?) @@ -252,6 +252,7 @@ fn pop_pinstall( } mod error { + use crate::Hooks; use hpk_package::tar; use std::{ error::Error, @@ -262,9 +263,6 @@ mod error { PoisonError, }, }; - - use crate::Hooks; - use super::InstallMessage; #[derive(Debug)]