Skip to content

Commit 87444d5

Browse files
ref(proguard): Use Chunked<ProguardMapping> for proguard upload
1 parent 2a3565e commit 87444d5

File tree

3 files changed

+37
-47
lines changed

3 files changed

+37
-47
lines changed

src/utils/chunks/types.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ where
9494
}
9595
}
9696

97+
impl<T> Assemblable for &T
98+
where
99+
T: Assemblable,
100+
{
101+
fn name(&self) -> Cow<str> {
102+
(*self).name()
103+
}
104+
105+
fn debug_id(&self) -> Option<DebugId> {
106+
(*self).debug_id()
107+
}
108+
}
109+
97110
impl<T> Assemblable for Chunked<T>
98111
where
99112
T: Assemblable,

src/utils/proguard/mapping.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
use symbolic::common::ByteView;
1+
use std::borrow::Cow;
2+
3+
use symbolic::common::{ByteView, DebugId};
24
use thiserror::Error;
35
use uuid::Uuid;
46

7+
use crate::utils::chunks::Assemblable;
8+
59
#[derive(Debug, Error)]
610
pub enum ProguardMappingError {
711
#[error("Proguard mapping does not contain line information")]
@@ -62,3 +66,13 @@ impl AsRef<[u8]> for ProguardMapping<'_> {
6266
self.bytes.as_ref()
6367
}
6468
}
69+
70+
impl Assemblable for ProguardMapping<'_> {
71+
fn name(&self) -> Cow<str> {
72+
format!("proguard/{}.txt", self.uuid).into()
73+
}
74+
75+
fn debug_id(&self) -> Option<DebugId> {
76+
None
77+
}
78+
}

src/utils/proguard/upload.rs

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
//! Proguard mappings, while we work on a more permanent solution, which will
55
//! work for all different types of debug files.
66
7-
use std::borrow::Cow;
87
use std::thread;
98
use std::time::{Duration, Instant};
109

1110
use anyhow::Result;
1211
use indicatif::ProgressStyle;
13-
use sha1_smol::Digest;
1412

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;
1816
use crate::utils::proguard::ProguardMapping;
1917

2018
/// 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);
2523
// usually was almost instantaneous, so this should probably be enough time.
2624
const ASSEMBLE_POLL_TIMEOUT: Duration = Duration::from_secs(120);
2725

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-
6526
/// Uploads a set of Proguard mappings to Sentry.
6627
/// Blocks until the mappings have been assembled (up to ASSEMBLE_POLL_TIMEOUT).
6728
/// Returns an error if the mappings fail to assemble, or if the timeout is reached.
@@ -71,17 +32,19 @@ pub fn chunk_upload(
7132
org: &str,
7233
project: &str,
7334
) -> Result<()> {
74-
let chunked_mappings: Vec<ChunkedMapping> = mappings
35+
let chunked_mappings = mappings
7536
.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<_>>>()?;
7839

7940
let progress_style = ProgressStyle::default_bar().template(
8041
"Uploading Proguard mappings...\
8142
\n{wide_bar} {bytes}/{total_bytes} ({eta})",
8243
);
8344

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());
8548

8649
chunks::upload_chunks(
8750
&chunks.collect::<Vec<_>>(),

0 commit comments

Comments
 (0)