4
4
//! Proguard mappings, while we work on a more permanent solution, which will
5
5
//! work for all different types of debug files.
6
6
7
- use std:: borrow:: Cow ;
8
7
use std:: thread;
9
8
use std:: time:: { Duration , Instant } ;
10
9
11
10
use anyhow:: Result ;
12
11
use indicatif:: ProgressStyle ;
13
- use sha1_smol:: Digest ;
14
12
15
- use crate :: api:: { Api , ChunkUploadOptions , ChunkedDifRequest , ChunkedFileState } ;
16
- use crate :: utils:: chunks:: { self , Chunk } ;
17
- use crate :: utils:: fs :: get_sha1_checksums ;
13
+ use crate :: api:: { Api , ChunkUploadOptions , ChunkedFileState } ;
14
+ use crate :: utils:: chunks;
15
+ use crate :: utils:: chunks :: Chunked ;
18
16
use crate :: utils:: proguard:: ProguardMapping ;
19
17
20
18
/// How often to poll the server for the status of the assembled mappings.
@@ -25,43 +23,6 @@ const ASSEMBLE_POLL_INTERVAL: Duration = Duration::from_secs(1);
25
23
// usually was almost instantaneous, so this should probably be enough time.
26
24
const ASSEMBLE_POLL_TIMEOUT : Duration = Duration :: from_secs ( 120 ) ;
27
25
28
- struct ChunkedMapping {
29
- raw_data : Vec < u8 > ,
30
- hash : Digest ,
31
- chunk_hashes : Vec < Digest > ,
32
- file_name : String ,
33
- chunk_size : usize ,
34
- }
35
-
36
- impl ChunkedMapping {
37
- fn try_from_mapping ( mapping : & ProguardMapping , chunk_size : u64 ) -> Result < Self > {
38
- let raw_data = mapping. as_ref ( ) . to_vec ( ) ;
39
- let file_name = format ! ( "/proguard/{}.txt" , mapping. uuid( ) ) ;
40
-
41
- let ( hash, chunk_hashes) = get_sha1_checksums ( & raw_data, chunk_size as usize ) ?;
42
- Ok ( Self {
43
- raw_data,
44
- hash,
45
- chunk_hashes,
46
- file_name,
47
- chunk_size : chunk_size. try_into ( ) ?,
48
- } )
49
- }
50
-
51
- fn chunks ( & self ) -> impl Iterator < Item = Chunk < ' _ > > {
52
- self . raw_data
53
- . chunks ( self . chunk_size )
54
- . zip ( self . chunk_hashes . iter ( ) )
55
- . map ( |( chunk, hash) | Chunk ( ( * hash, chunk) ) )
56
- }
57
- }
58
-
59
- impl < ' a > From < & ' a ChunkedMapping > for ChunkedDifRequest < ' a > {
60
- fn from ( value : & ' a ChunkedMapping ) -> Self {
61
- ChunkedDifRequest :: new ( Cow :: from ( & value. file_name ) , & value. chunk_hashes , value. hash )
62
- }
63
- }
64
-
65
26
/// Uploads a set of Proguard mappings to Sentry.
66
27
/// Blocks until the mappings have been assembled (up to ASSEMBLE_POLL_TIMEOUT).
67
28
/// Returns an error if the mappings fail to assemble, or if the timeout is reached.
@@ -71,17 +32,19 @@ pub fn chunk_upload(
71
32
org : & str ,
72
33
project : & str ,
73
34
) -> Result < ( ) > {
74
- let chunked_mappings: Vec < ChunkedMapping > = mappings
35
+ let chunked_mappings = mappings
75
36
. iter ( )
76
- . map ( |mapping| ChunkedMapping :: try_from_mapping ( mapping, chunk_upload_options. chunk_size ) )
77
- . collect :: < Result < _ > > ( ) ?;
37
+ . map ( |mapping| Chunked :: from ( mapping, chunk_upload_options. chunk_size as usize ) )
38
+ . collect :: < Result < Vec < _ > > > ( ) ?;
78
39
79
40
let progress_style = ProgressStyle :: default_bar ( ) . template (
80
41
"Uploading Proguard mappings...\
81
42
\n {wide_bar} {bytes}/{total_bytes} ({eta})",
82
43
) ;
83
44
84
- let chunks = chunked_mappings. iter ( ) . flat_map ( |mapping| mapping. chunks ( ) ) ;
45
+ let chunks = chunked_mappings
46
+ . iter ( )
47
+ . flat_map ( |mapping| mapping. iter_chunks ( ) ) ;
85
48
86
49
chunks:: upload_chunks (
87
50
& chunks. collect :: < Vec < _ > > ( ) ,
0 commit comments