1- use std:: env;
21use std:: io;
32
43use anyhow:: { bail, Error , Result } ;
@@ -9,16 +8,13 @@ use symbolic::common::ByteView;
98use uuid:: Uuid ;
109
1110use crate :: api:: Api ;
11+ use crate :: api:: ChunkUploadCapability ;
1212use crate :: config:: Config ;
1313use crate :: utils:: android:: dump_proguard_uuids_as_properties;
1414use crate :: utils:: args:: ArgExt as _;
15- use crate :: utils:: fs:: TempFile ;
1615use crate :: utils:: proguard;
1716use crate :: utils:: proguard:: ProguardMapping ;
1817use crate :: utils:: system:: QuietExit ;
19- use crate :: utils:: ui:: { copy_with_progress, make_byte_progress_bar} ;
20-
21- const CHUNK_UPLOAD_ENV_VAR : & str = "SENTRY_EXPERIMENTAL_PROGUARD_CHUNK_UPLOAD" ;
2218
2319pub fn make_command ( command : Command ) -> Command {
2420 command
@@ -167,79 +163,31 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
167163 let api = Api :: current ( ) ;
168164 let config = Config :: current ( ) ;
169165
170- // Don't initialize these until we confirm the user did not pass the --no-upload flag,
171- // or if we are using chunked uploading. This is because auth token, org, and project
172- // are not needed for the no-upload case.
173- let authenticated_api;
174- let ( org, project) ;
175-
176- if env:: var ( CHUNK_UPLOAD_ENV_VAR ) == Ok ( "1" . into ( ) ) {
177- log:: warn!(
178- "EXPERIMENTAL FEATURE: Uploading proguard mappings using chunked uploading. \
179- Some functionality may be unavailable when using chunked uploading. Please unset \
180- the {CHUNK_UPLOAD_ENV_VAR} variable if you encounter any \
181- problems."
182- ) ;
183-
184- authenticated_api = api. authenticated ( ) ?;
185- ( org, project) = config. get_org_and_project ( matches) ?;
186-
187- let chunk_upload_options = authenticated_api. get_chunk_upload_options ( & org) ?;
188-
189- proguard:: chunk_upload ( & mappings, chunk_upload_options, & org, & project) ?;
190- } else {
191- if mappings. is_empty ( ) && matches. get_flag ( "require_one" ) {
192- println ! ( ) ;
193- eprintln ! ( "{}" , style( "error: found no mapping files to upload" ) . red( ) ) ;
194- return Err ( QuietExit ( 1 ) . into ( ) ) ;
195- }
196-
197- println ! ( "{} compressing mappings" , style( ">" ) . dim( ) ) ;
198- let tf = TempFile :: create ( ) ?;
199- {
200- let mut zip = zip:: ZipWriter :: new ( tf. open ( ) ?) ;
201- for mapping in & mappings {
202- let pb = make_byte_progress_bar ( mapping. len ( ) as u64 ) ;
203- zip. start_file (
204- format ! ( "proguard/{}.txt" , mapping. uuid( ) ) ,
205- zip:: write:: SimpleFileOptions :: default ( ) ,
206- ) ?;
207- copy_with_progress ( & pb, & mut mapping. as_ref ( ) , & mut zip) ?;
208- pb. finish_and_clear ( ) ;
209- }
210- }
166+ if mappings. is_empty ( ) && matches. get_flag ( "require_one" ) {
167+ println ! ( ) ;
168+ eprintln ! ( "{}" , style( "error: found no mapping files to upload" ) . red( ) ) ;
169+ return Err ( QuietExit ( 1 ) . into ( ) ) ;
170+ }
211171
212- // write UUIDs into the mapping file.
213- if let Some ( p) = matches. get_one :: < String > ( "write_properties" ) {
214- let uuids: Vec < _ > = mappings. iter ( ) . map ( |x| x. uuid ( ) ) . collect ( ) ;
215- dump_proguard_uuids_as_properties ( p, & uuids) ?;
216- }
172+ // write UUIDs into the mapping file.
173+ if let Some ( p) = matches. get_one :: < String > ( "write_properties" ) {
174+ let uuids: Vec < _ > = mappings. iter ( ) . map ( |x| x. uuid ( ) ) . collect ( ) ;
175+ dump_proguard_uuids_as_properties ( p, & uuids) ?;
176+ }
217177
218- if matches. get_flag ( "no_upload" ) {
219- println ! ( "{} skipping upload." , style( ">" ) . dim( ) ) ;
220- return Ok ( ( ) ) ;
221- }
178+ if matches. get_flag ( "no_upload" ) {
179+ println ! ( "{} skipping upload." , style( ">" ) . dim( ) ) ;
180+ return Ok ( ( ) ) ;
181+ }
222182
223- println ! ( "{} uploading mappings" , style ( ">" ) . dim ( ) ) ;
224- ( org, project) = config. get_org_and_project ( matches) ?;
183+ let authenticated_api = api . authenticated ( ) ? ;
184+ let ( org, project) = config. get_org_and_project ( matches) ?;
225185
226- authenticated_api = api . authenticated ( ) ?;
186+ let chunk_upload_options = authenticated_api . get_chunk_upload_options ( & org ) ?;
227187
228- let rv = authenticated_api
229- . region_specific ( & org)
230- . upload_dif_archive ( & project, tf. path ( ) ) ?;
231- println ! (
232- "{} Uploaded a total of {} new mapping files" ,
233- style( ">" ) . dim( ) ,
234- style( rv. len( ) ) . yellow( )
235- ) ;
236- if !rv. is_empty ( ) {
237- println ! ( "Newly uploaded debug symbols:" ) ;
238- for df in rv {
239- println ! ( " {}" , style( & df. id( ) ) . dim( ) ) ;
240- }
241- }
188+ if chunk_upload_options. supports ( ChunkUploadCapability :: Proguard ) {
189+ proguard:: chunk_upload ( & mappings, chunk_upload_options, & org, & project)
190+ } else {
191+ Err ( anyhow:: anyhow!( "Server does not support uploading ProGuard mappings via chunked upload. Please update your Sentry server." ) )
242192 }
243-
244- Ok ( ( ) )
245193}
0 commit comments