1111use std:: {
1212 path:: { Path , PathBuf } ,
1313 process,
14+ sync:: atomic:: { AtomicUsize , Ordering } ,
1415} ;
1516
1617use crate :: Installation ;
@@ -107,10 +108,9 @@ pub(super) struct TriggerRunner {
107108
108109/// Progress callback handler
109110#[ derive( Debug , Clone ) ]
110- pub struct Progress {
111- pub in_progress : usize ,
111+ pub struct Progress < ' a > {
112112 pub completed : u64 ,
113- pub items : Vec < String > ,
113+ pub item : & ' a str ,
114114}
115115
116116/// Load all triggers matching the given scope and staging filesystem, return in batches
@@ -167,7 +167,7 @@ pub(super) fn triggers<'a>(
167167pub fn execute_triggers (
168168 scope : TriggerScope < ' _ > ,
169169 triggers : & [ Vec < TriggerRunner > ] ,
170- on_progress : impl Fn ( Progress ) + Send + Sync ,
170+ on_progress : impl Fn ( Progress < ' _ > ) + Send + Sync ,
171171) -> Result < ( ) , Error > {
172172 match scope {
173173 TriggerScope :: Transaction ( install, scope) => {
@@ -193,7 +193,7 @@ fn execute_transaction_triggers<P>(
193193 on_progress : P ,
194194) -> Result < ( ) , Error >
195195where
196- P : Fn ( Progress ) + Send + Sync ,
196+ P : Fn ( Progress < ' _ > ) + Send + Sync ,
197197{
198198 let trigger_scope = TriggerScope :: Transaction ( install, scope) ;
199199 // TODO: Add caching support via /var/
@@ -221,7 +221,7 @@ fn execute_system_triggers<P>(
221221 on_progress : P ,
222222) -> Result < ( ) , Error >
223223where
224- P : Fn ( Progress ) + Send + Sync ,
224+ P : Fn ( Progress < ' _ > ) + Send + Sync ,
225225{
226226 let trigger_scope = TriggerScope :: System ( install, scope) ;
227227
@@ -253,23 +253,22 @@ impl TriggerRunner {
253253/// Internal executor for triggers.
254254fn execute_triggers_directly < P > ( triggers : & [ Vec < TriggerRunner > ] , on_progress : P ) -> Result < ( ) , Error >
255255where
256- P : Fn ( Progress ) + Send + Sync ,
256+ P : Fn ( Progress < ' _ > ) + Send + Sync ,
257257{
258258 let rayon_runtime = rayon:: ThreadPoolBuilder :: new ( ) . build ( ) . expect ( "rayon runtime" ) ;
259- let total = 0 ;
259+
260+ let counter = AtomicUsize :: new ( 0 ) ;
261+
260262 rayon_runtime. install ( || {
261263 triggers. iter ( ) . try_for_each ( |batch| {
262264 batch. par_iter ( ) . try_for_each ( |trigger| {
265+ let completed = counter. fetch_add ( 1 , Ordering :: Relaxed ) ;
263266 ( on_progress) ( Progress {
264- in_progress : batch. len ( ) ,
265- completed : total + 1 ,
266- items : batch
267- . iter ( )
268- . map ( |t| match t. handler ( ) {
269- Handler :: Run { run, .. } => run. clone ( ) ,
270- Handler :: Delete { .. } => "delete operation" . to_owned ( ) ,
271- } )
272- . collect ( ) ,
267+ completed : completed as u64 ,
268+ item : match trigger. handler ( ) {
269+ Handler :: Run { run, .. } => run,
270+ Handler :: Delete { .. } => "delete operation" ,
271+ } ,
273272 } ) ;
274273 execute_trigger_directly ( trigger. trigger ( ) )
275274 } )
0 commit comments