diff --git a/src/utils/chunks/mod.rs b/src/utils/chunks/mod.rs index 7d01762864..f17a9792a1 100644 --- a/src/utils/chunks/mod.rs +++ b/src/utils/chunks/mod.rs @@ -6,8 +6,10 @@ //! See `BatchedSliceExt::batches` for more information. mod types; +mod upload; pub use types::{Assemblable, Chunked, MissingObjectsInfo}; +pub use upload::ChunkOptions; use std::sync::Arc; use std::time::Duration; diff --git a/src/utils/chunks/upload.rs b/src/utils/chunks/upload.rs new file mode 100644 index 0000000000..663a7044ee --- /dev/null +++ b/src/utils/chunks/upload.rs @@ -0,0 +1,14 @@ +/// A trait representing options for chunk uploads. +pub trait ChunkOptions { + /// Determines whether we need to strip debug_ids from the requests. + /// When this function returns `true`, the caller is responsible for stripping + /// the debug_ids from the requests, to maintain backwards compatibility with + /// older Sentry servers. + fn should_strip_debug_ids(&self) -> bool; + + /// Returns the organization that we are uploading to. + fn org(&self) -> &str; + + /// Returns the project that we are uploading to. + fn project(&self) -> &str; +} diff --git a/src/utils/dif_upload.rs b/src/utils/dif_upload.rs index dd109e1394..a8c70c5aaf 100644 --- a/src/utils/dif_upload.rs +++ b/src/utils/dif_upload.rs @@ -39,8 +39,8 @@ use crate::api::{ use crate::config::Config; use crate::constants::{DEFAULT_MAX_DIF_SIZE, DEFAULT_MAX_WAIT}; use crate::utils::chunks::{ - upload_chunks, Assemblable, BatchedSliceExt, Chunk, Chunked, ItemSize, MissingObjectsInfo, - ASSEMBLE_POLL_INTERVAL, + upload_chunks, Assemblable, BatchedSliceExt, Chunk, ChunkOptions, Chunked, ItemSize, + MissingObjectsInfo, ASSEMBLE_POLL_INTERVAL, }; use crate::utils::dif::ObjectDifFeatures; use crate::utils::fs::{get_sha1_checksum, TempDir, TempFile}; @@ -1229,7 +1229,7 @@ fn create_il2cpp_mappings<'a>(difs: &[DifMatch<'a>]) -> Result> /// missing chunks for convenience. fn try_assemble<'m, T>( objects: &'m [Chunked], - options: &DifUpload, + options: &impl ChunkOptions, ) -> Result> where T: AsRef<[u8]> + Assemblable, @@ -1237,13 +1237,13 @@ where let api = Api::current(); let mut request: AssembleDifsRequest<'_> = objects.iter().collect(); - if !options.pdbs_allowed { + if options.should_strip_debug_ids() { request.strip_debug_ids(); } - let response = api - .authenticated()? - .assemble_difs(&options.org, &options.project, &request)?; + let response = + api.authenticated()? + .assemble_difs(options.org(), options.project(), &request)?; // We map all DIFs by their checksum, so we can access them faster when // iterating through the server response below. Since the caller will invoke @@ -2090,3 +2090,22 @@ impl DifUpload { true } } + +impl ChunkOptions for DifUpload { + fn should_strip_debug_ids(&self) -> bool { + // We need to strip the debug_ids whenever the server does not support + // chunked uploading of PDBs, to maintain backwards compatibility. + // + // See: https://github.com/getsentry/sentry-cli/issues/980 + // See: https://github.com/getsentry/sentry-cli/issues/1056 + !self.pdbs_allowed + } + + fn org(&self) -> &str { + &self.org + } + + fn project(&self) -> &str { + &self.project + } +}