1
1
//! Searches, processes and uploads release files.
2
2
use std:: collections:: { BTreeMap , HashMap } ;
3
- use std:: fmt;
3
+ use std:: fmt:: { self , Display } ;
4
4
use std:: io:: BufWriter ;
5
5
use std:: path:: PathBuf ;
6
6
use std:: str;
@@ -19,6 +19,7 @@ use symbolic::common::ByteView;
19
19
use symbolic:: debuginfo:: sourcebundle:: {
20
20
SourceBundleErrorKind , SourceBundleWriter , SourceFileInfo , SourceFileType ,
21
21
} ;
22
+ use thiserror:: Error ;
22
23
use url:: Url ;
23
24
24
25
use crate :: api:: NewRelease ;
@@ -100,6 +101,89 @@ impl UploadContext<'_> {
100
101
}
101
102
}
102
103
104
+ #[ derive( Debug , Error ) ]
105
+ #[ non_exhaustive]
106
+ pub enum LegacyUploadContextError {
107
+ #[ error( "A release is required for this upload" ) ]
108
+ ReleaseMissing ,
109
+ }
110
+
111
+ #[ derive( Debug , Default ) ]
112
+ pub struct LegacyUploadContext < ' a > {
113
+ org : & ' a str ,
114
+ project : Option < & ' a str > ,
115
+ release : & ' a str ,
116
+ dist : Option < & ' a str > ,
117
+ }
118
+
119
+ impl LegacyUploadContext < ' _ > {
120
+ pub fn org ( & self ) -> & str {
121
+ self . org
122
+ }
123
+
124
+ pub fn project ( & self ) -> Option < & str > {
125
+ self . project
126
+ }
127
+
128
+ pub fn release ( & self ) -> & str {
129
+ self . release
130
+ }
131
+
132
+ pub fn dist ( & self ) -> Option < & str > {
133
+ self . dist
134
+ }
135
+ }
136
+
137
+ impl Display for LegacyUploadContext < ' _ > {
138
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
139
+ writeln ! (
140
+ f,
141
+ "{} {}" ,
142
+ style( "> Organization:" ) . dim( ) ,
143
+ style( self . org) . yellow( )
144
+ ) ?;
145
+ writeln ! (
146
+ f,
147
+ "{} {}" ,
148
+ style( "> Project:" ) . dim( ) ,
149
+ style( self . project. unwrap_or( "None" ) ) . yellow( )
150
+ ) ?;
151
+ writeln ! (
152
+ f,
153
+ "{} {}" ,
154
+ style( "> Release:" ) . dim( ) ,
155
+ style( self . release) . yellow( )
156
+ ) ?;
157
+ writeln ! (
158
+ f,
159
+ "{} {}" ,
160
+ style( "> Dist:" ) . dim( ) ,
161
+ style( self . dist. unwrap_or( "None" ) ) . yellow( )
162
+ ) ?;
163
+ write ! (
164
+ f,
165
+ "{} {}" ,
166
+ style( "> Upload type:" ) . dim( ) ,
167
+ style( "single file/legacy upload" ) . yellow( )
168
+ )
169
+ }
170
+ }
171
+
172
+ impl < ' a > TryFrom < & ' a UploadContext < ' _ > > for LegacyUploadContext < ' a > {
173
+ type Error = LegacyUploadContextError ;
174
+
175
+ fn try_from ( value : & ' a UploadContext ) -> Result < Self , Self :: Error > {
176
+ Ok ( LegacyUploadContext {
177
+ org : value. org ,
178
+ project : value. project ,
179
+ release : value
180
+ . release
181
+ . ok_or ( LegacyUploadContextError :: ReleaseMissing ) ?,
182
+ dist : value. dist ,
183
+ } )
184
+ }
185
+ }
186
+
103
187
#[ derive( Eq , PartialEq , Debug , Copy , Clone ) ]
104
188
pub enum LogLevel {
105
189
Warning ,
@@ -215,7 +299,7 @@ impl<'a> FileUpload<'a> {
215
299
. context
216
300
. chunk_upload_options
217
301
. map_or ( DEFAULT_CONCURRENCY , |o| usize:: from ( o. concurrency ) ) ;
218
- upload_files_parallel ( self . context , & self . files , concurrency)
302
+ upload_files_parallel ( & self . context . try_into ( ) ? , & self . files , concurrency)
219
303
}
220
304
221
305
pub fn build_jvm_bundle ( & self , debug_id : Option < DebugId > ) -> Result < TempFile > {
@@ -224,18 +308,18 @@ impl<'a> FileUpload<'a> {
224
308
}
225
309
226
310
fn upload_files_parallel (
227
- context : & UploadContext ,
311
+ context : & LegacyUploadContext ,
228
312
files : & SourceFiles ,
229
313
num_threads : usize ,
230
314
) -> Result < ( ) > {
231
315
let api = Api :: current ( ) ;
232
- let release = context. release ( ) ? ;
316
+ let release = context. release ( ) ;
233
317
234
318
// get a list of release files first so we know the file IDs of
235
319
// files that already exist.
236
320
let release_files: HashMap < _ , _ > = api
237
321
. authenticated ( ) ?
238
- . list_release_files ( context. org , context. project , release) ?
322
+ . list_release_files ( context. org , context. project ( ) , release) ?
239
323
. into_iter ( )
240
324
. map ( |artifact| ( ( artifact. dist , artifact. name ) , artifact. id ) )
241
325
. collect ( ) ;
@@ -308,7 +392,7 @@ fn upload_files_parallel(
308
392
309
393
pb. finish_and_clear ( ) ;
310
394
311
- print_upload_context_details ( context) ;
395
+ println ! ( "{}" , context) ;
312
396
313
397
Ok ( ( ) )
314
398
}
0 commit comments