@@ -45,6 +45,7 @@ struct thread_data {
4545 unsigned int slicecount ;
4646 int (* fn )(struct xbps_handle * , xbps_object_t , const char * , void * , bool * );
4747 void * fn_arg ;
48+ int r ;
4849};
4950
5051/**
@@ -61,7 +62,7 @@ array_foreach_thread(void *arg)
6162 xbps_object_t obj , pkgd ;
6263 struct thread_data * thd = arg ;
6364 const char * key ;
64- int rv ;
65+ int r ;
6566 bool loop_done = false;
6667 unsigned i = thd -> start ;
6768 unsigned int end = i + thd -> slicecount ;
@@ -80,9 +81,11 @@ array_foreach_thread(void *arg)
8081 pkgd = obj ;
8182 key = NULL ;
8283 }
83- rv = (* thd -> fn )(thd -> xhp , pkgd , key , thd -> fn_arg , & loop_done );
84- if (rv != 0 || loop_done )
84+ r = (* thd -> fn )(thd -> xhp , pkgd , key , thd -> fn_arg , & loop_done );
85+ if (r != 0 || loop_done ) {
86+ thd -> r = r ;
8587 return NULL ;
88+ }
8689 }
8790 /* Reserve more elements to compute */
8891 pthread_mutex_lock (thd -> reserved_lock );
@@ -171,10 +174,23 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
171174 }
172175 }
173176
174- free (thd );
175177 pthread_mutex_destroy (& reserved_lock );
176178
177- return error ? - EIO : 0 ;
179+ if (error != 0 ) {
180+ free (thd );
181+ return - EAGAIN ;
182+ }
183+
184+ r = 0 ;
185+ for (int j = 0 ; j < i ; j ++ ) {
186+ if (thd [i ].r == 0 )
187+ continue ;
188+ r = thd [i ].r ;
189+ break ;
190+ }
191+
192+ free (thd );
193+ return r ;
178194}
179195
180196int
@@ -187,7 +203,7 @@ xbps_array_foreach_cb(struct xbps_handle *xhp,
187203 xbps_dictionary_t pkgd ;
188204 xbps_object_t obj ;
189205 const char * key ;
190- int rv = 0 ;
206+ int r = 0 ;
191207 bool loop_done = false;
192208
193209 for (unsigned int i = 0 ; i < xbps_array_count (array ); i ++ ) {
@@ -202,11 +218,11 @@ xbps_array_foreach_cb(struct xbps_handle *xhp,
202218 pkgd = obj ;
203219 key = NULL ;
204220 }
205- rv = (* fn )(xhp , pkgd , key , arg , & loop_done );
206- if (rv != 0 || loop_done )
207- break ;
221+ r = (* fn )(xhp , pkgd , key , arg , & loop_done );
222+ if (r != 0 || loop_done )
223+ return r ;
208224 }
209- return rv ;
225+ return 0 ;
210226}
211227
212228xbps_object_iterator_t
0 commit comments