Skip to content

Commit 0c834b2

Browse files
ref(sourcebundle): Only take sourcefile values (#2925)
### Description Minor simplification of only taking the `SourceFile` values, as we don't need the &SourceFiles type (which is a type alias for `BTreeMap` ### Issues - See #2927 - See [CLI-220](https://linear.app/getsentry/issue/CLI-220/dont-call-chunk-upload-for-bundle-jvm)
1 parent bd33a24 commit 0c834b2

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/utils/file_upload.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'a> FileUpload<'a> {
411411
}
412412

413413
pub fn build_jvm_bundle(&self, debug_id: Option<DebugId>) -> Result<TempFile> {
414-
source_bundle::build(self.context, &self.files, debug_id)
414+
source_bundle::build(self.context, self.files.values(), debug_id)
415415
}
416416
}
417417

@@ -618,7 +618,7 @@ fn upload_files_chunked(
618618
files: &SourceFiles,
619619
options: &ChunkServerOptions,
620620
) -> Result<()> {
621-
let archive = source_bundle::build(context, files, None)?;
621+
let archive = source_bundle::build(context, files.values(), None)?;
622622

623623
let progress_style =
624624
ProgressStyle::default_spinner().template("{spinner} Optimizing bundle for upload...");

src/utils/source_bundle.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Borrow;
12
use std::io::BufWriter;
23

34
use anyhow::Result;
@@ -8,7 +9,7 @@ use symbolic::debuginfo::sourcebundle::{
89
};
910
use url::Url;
1011

11-
use crate::utils::file_upload::{SourceFiles, UploadContext};
12+
use crate::utils::file_upload::{SourceFile, UploadContext};
1213
use crate::utils::fs::TempFile;
1314
use crate::utils::non_empty::NonEmptySlice;
1415
use crate::utils::progress::ProgressBar;
@@ -38,11 +39,15 @@ impl<'a> From<&'a UploadContext<'a>> for BundleContext<'a> {
3839
/// from the upload context.
3940
///
4041
/// Returns a `TempFile` containing the source bundle.
41-
pub fn build<'a, C>(context: C, files: &SourceFiles, debug_id: Option<DebugId>) -> Result<TempFile>
42+
pub fn build<'a, C, F, S>(context: C, files: F, debug_id: Option<DebugId>) -> Result<TempFile>
4243
where
4344
C: Into<BundleContext<'a>>,
45+
F: IntoIterator<Item = S>,
46+
S: Borrow<SourceFile>,
4447
{
4548
let context = context.into();
49+
let files = files.into_iter().collect::<Vec<_>>();
50+
4651
let progress_style = ProgressStyle::default_bar().template(
4752
"{prefix:.dim} Bundling files for upload... {msg:.dim}\
4853
\n{wide_bar} {pos}/{len}",
@@ -56,7 +61,7 @@ where
5661
let mut bundle = SourceBundleWriter::start(BufWriter::new(archive.open()?))?;
5762

5863
// source bundles get a random UUID as debug id
59-
let debug_id = debug_id.unwrap_or_else(|| build_debug_id(files));
64+
let debug_id = debug_id.unwrap_or_else(|| build_debug_id(&files));
6065
bundle.set_attribute("debug_id", debug_id.to_string());
6166

6267
if let Some(note) = context.note {
@@ -77,7 +82,7 @@ where
7782

7883
let mut bundle_file_count = 0;
7984

80-
for file in files.values() {
85+
for file in files.iter().map(Borrow::borrow) {
8186
pb.inc(1);
8287
pb.set_message(&file.url);
8388

@@ -128,9 +133,12 @@ where
128133

129134
/// Creates a debug id from a map of source files by hashing each file's
130135
/// URL, contents, type, and headers.
131-
fn build_debug_id(files: &SourceFiles) -> DebugId {
136+
fn build_debug_id<S>(files: &[S]) -> DebugId
137+
where
138+
S: Borrow<SourceFile>,
139+
{
132140
let mut hash = sha1_smol::Sha1::new();
133-
for source_file in files.values() {
141+
for source_file in files.iter().map(Borrow::borrow) {
134142
hash.update(source_file.url.as_bytes());
135143
hash.update(&source_file.contents);
136144
hash.update(format!("{:?}", source_file.ty).as_bytes());
@@ -216,21 +224,18 @@ mod tests {
216224

217225
let source_files = ["bundle.min.js.map", "vendor.min.js.map"]
218226
.into_iter()
219-
.map(|name| {
220-
let file = SourceFile {
221-
url: format!("~/{name}"),
222-
path: format!("tests/integration/_fixtures/{name}").into(),
223-
contents: std::fs::read(format!("tests/integration/_fixtures/{name}"))
224-
.unwrap()
225-
.into(),
226-
ty: SourceFileType::SourceMap,
227-
headers: Default::default(),
228-
messages: Default::default(),
229-
already_uploaded: false,
230-
};
231-
(format!("~/{name}"), file)
227+
.map(|name| SourceFile {
228+
url: format!("~/{name}"),
229+
path: format!("tests/integration/_fixtures/{name}").into(),
230+
contents: std::fs::read(format!("tests/integration/_fixtures/{name}"))
231+
.unwrap()
232+
.into(),
233+
ty: SourceFileType::SourceMap,
234+
headers: Default::default(),
235+
messages: Default::default(),
236+
already_uploaded: false,
232237
})
233-
.collect();
238+
.collect::<Vec<_>>();
234239

235240
let file = build(context, &source_files, None).unwrap();
236241

0 commit comments

Comments
 (0)