@@ -27,7 +27,6 @@ use tokio::task::JoinSet;
27
27
/// If an error occurs with a resolving task, instead of failing immediately,
28
28
/// resolution will continue and the error return flag is set to true.
29
29
pub async fn get_platform_downloadables ( profile : & Profile ) -> Result < ( Vec < DownloadData > , bool ) > {
30
- let to_download = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
31
30
let progress_bar = Arc :: new ( Mutex :: new ( ProgressBar :: new ( 0 ) . with_style ( STYLE_NO . clone ( ) ) ) ) ;
32
31
let mut tasks = JoinSet :: new ( ) ;
33
32
let mut done_mods = Vec :: new ( ) ;
@@ -73,11 +72,10 @@ pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<Downlo
73
72
74
73
let filters = profile. filters . clone ( ) ;
75
74
let dep_sender = Arc :: clone ( & mod_sender) ;
76
- let to_download = Arc :: clone ( & to_download) ;
77
75
let progress_bar = Arc :: clone ( & progress_bar) ;
78
76
79
77
tasks. spawn ( async move {
80
- let permit = SEMAPHORE . get_or_init ( default_semaphore) . acquire ( ) . await ?;
78
+ let permit = SEMAPHORE . get_or_init ( default_semaphore) . acquire ( ) . await ?;
81
79
82
80
let result = mod_. fetch_download_file ( filters) . await ;
83
81
@@ -114,8 +112,7 @@ pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<Downlo
114
112
false ,
115
113
) ) ?;
116
114
}
117
- to_download. lock ( ) . push ( download_file) ;
118
- Ok ( true )
115
+ Ok ( Some ( download_file) )
119
116
}
120
117
Err ( err) => {
121
118
if let mod_downloadable:: Error :: ModrinthError (
@@ -130,29 +127,28 @@ pub async fn get_platform_downloadables(profile: &Profile) -> Result<(Vec<Downlo
130
127
"{}" ,
131
128
format!( "{CROSS} {:pad_len$} {err}" , mod_. name) . red( )
132
129
) ) ;
133
- Ok ( false )
130
+ Ok ( None )
134
131
}
135
132
}
136
133
} ) ;
137
134
}
138
135
}
139
136
140
- let error = tasks
141
- . join_all ( )
142
- . await
143
- . iter ( )
144
- . any ( |r| matches ! ( r, Ok ( false ) ) ) ;
145
-
146
137
Arc :: try_unwrap ( progress_bar)
147
138
. map_err ( |_| anyhow ! ( "Failed to run threads to completion" ) ) ?
148
139
. into_inner ( )
149
140
. finish_and_clear ( ) ;
150
- Ok ( (
151
- Arc :: try_unwrap ( to_download)
152
- . map_err ( |_| anyhow ! ( "Failed to run threads to completion" ) ) ?
153
- . into_inner ( ) ,
154
- error,
155
- ) )
141
+
142
+ let tasks = tasks
143
+ . join_all ( )
144
+ . await
145
+ . into_iter ( )
146
+ . collect :: < Result < Vec < _ > > > ( ) ?;
147
+
148
+ let error = tasks. iter ( ) . any ( Option :: is_none) ;
149
+ let to_download = tasks. into_iter ( ) . flatten ( ) . collect ( ) ;
150
+
151
+ Ok ( ( to_download, error) )
156
152
}
157
153
158
154
pub async fn upgrade ( profile : & Profile ) -> Result < ( ) > {
0 commit comments