Use `try_for_each_with` in `Installer::install` to avoid using a mutex

on the Sender.
This commit is contained in:
Nathan Fisher 2023-04-12 11:25:12 -04:00
parent d3b5d096e5
commit c36b3b14ab
2 changed files with 5 additions and 9 deletions

View File

@ -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,

View File

@ -100,9 +100,9 @@ impl<T: io::Read> Installer<T> {
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<T: io::Read> Installer<T> {
}
}
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)]