Skip to content

Commit 965a6da

Browse files
Merge branch 'master' into szokeasaurusrex/implicit-clone
2 parents 8a3c176 + 4cda688 commit 965a6da

9 files changed

Lines changed: 36 additions & 37 deletions

File tree

src/api/data_types/chunking/upload/options.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::num::NonZeroUsize;
2+
13
use serde::Deserialize;
24

35
use super::{ChunkCompression, ChunkHashAlgorithm, ChunkUploadCapability};
@@ -17,7 +19,7 @@ pub struct ChunkServerOptions {
1719
pub max_wait: u64,
1820
#[expect(dead_code)]
1921
pub hash_algorithm: ChunkHashAlgorithm,
20-
pub chunk_size: u64,
22+
pub chunk_size: NonZeroUsize,
2123
pub concurrency: u8,
2224
#[serde(default)]
2325
pub compression: Vec<ChunkCompression>,

src/commands/build/upload.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,10 @@ fn upload_file(
507507
pb.enable_steady_tick(100);
508508
pb.set_style(progress_style);
509509

510-
let chunk_size = chunk_upload_options.chunk_size as usize;
511-
let (checksum, checksums) = get_sha1_checksums(bytes, chunk_size)?;
510+
let chunk_size = chunk_upload_options.chunk_size;
511+
let (checksum, checksums) = get_sha1_checksums(bytes, chunk_size);
512512
let mut chunks = bytes
513-
.chunks(chunk_size)
513+
.chunks(chunk_size.into())
514514
.zip(checksums.iter())
515515
.map(|(data, checksum)| Chunk((*checksum, data)))
516516
.collect::<Vec<_>>();

src/commands/dart_symbol_map/upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub(super) fn execute(args: DartSymbolMapUploadArgs) -> Result<()> {
159159
let options = ChunkOptions::new(chunk_upload_options, org, project)
160160
.with_max_wait(DEFAULT_MAX_WAIT);
161161

162-
let chunked = Chunked::from(object, options.server_options().chunk_size as usize)?;
162+
let chunked = Chunked::from(object, options.server_options().chunk_size);
163163
let (_uploaded, has_processing_errors) = upload_chunked_objects(&[chunked], options)?;
164164
if has_processing_errors {
165165
bail!("Some symbol maps did not process correctly");

src/commands/upload_proguard.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
214214
}
215215
}
216216

217+
// We are done constructing the mappings, redeclare as immutable.
218+
let mappings = mappings;
219+
217220
let api = Api::current();
218221
let config = Config::current();
219222

src/utils/chunks/types.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use std::borrow::Cow;
44
use std::fmt::{Display, Formatter, Result as FmtResult};
5+
use std::num::NonZeroUsize;
56

6-
use anyhow::Result;
77
use sha1_smol::Digest;
88
use symbolic::common::DebugId;
99

@@ -37,7 +37,7 @@ pub struct Chunked<T> {
3737
chunks: Vec<Digest>,
3838

3939
/// Size of a single chunk
40-
chunk_size: usize,
40+
chunk_size: NonZeroUsize,
4141
}
4242

4343
impl<T> Chunked<T> {
@@ -63,14 +63,14 @@ where
6363
{
6464
/// Creates a new `ChunkedObject` from the given object, using
6565
/// the given chunk size.
66-
pub fn from(object: T, chunk_size: usize) -> Result<Self> {
67-
let (checksum, chunks) = fs::get_sha1_checksums(object.as_ref(), chunk_size)?;
68-
Ok(Self {
66+
pub fn from(object: T, chunk_size: NonZeroUsize) -> Self {
67+
let (checksum, chunks) = fs::get_sha1_checksums(object.as_ref(), chunk_size);
68+
Self {
6969
object,
7070
checksum,
7171
chunks,
7272
chunk_size,
73-
})
73+
}
7474
}
7575

7676
/// Returns an iterator over all chunks of the object.
@@ -79,7 +79,7 @@ where
7979
pub fn iter_chunks(&self) -> impl Iterator<Item = Chunk<'_>> {
8080
self.object
8181
.as_ref()
82-
.chunks(self.chunk_size)
82+
.chunks(self.chunk_size.into())
8383
.zip(self.chunk_hashes().iter())
8484
.map(|(data, checksum)| Chunk((*checksum, data)))
8585
}

src/utils/dif_upload/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,10 @@ fn upload_difs_chunked(
12361236
processed.extend(source_bundles);
12371237
}
12381238

1239+
let chunk_size = chunk_options.chunk_size;
1240+
12391241
// Calculate checksums and chunks
1240-
let chunked = prepare_difs(processed, |m| {
1241-
Chunked::from(m, chunk_options.chunk_size as usize)
1242-
})?;
1242+
let chunked = prepare_difs(processed, |m| Ok(Chunked::from(m, chunk_size)))?;
12431243

12441244
if options.no_upload {
12451245
println!("{} skipping upload.", style(">").dim());

src/utils/file_upload.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,9 @@ fn upload_files_chunked(
638638
pb.set_style(progress_style);
639639

640640
let view = ByteView::open(archive.path())?;
641-
let (checksum, checksums) = get_sha1_checksums(&view, options.chunk_size as usize)?;
641+
let (checksum, checksums) = get_sha1_checksums(&view, options.chunk_size);
642642
let mut chunks = view
643-
.chunks(options.chunk_size as usize)
643+
.chunks(options.chunk_size.into())
644644
.zip(checksums.iter())
645645
.map(|(data, checksum)| Chunk((*checksum, data)))
646646
.collect::<Vec<_>>();

src/utils/fs.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use std::env;
22
use std::fs;
33
use std::io;
44
use std::io::{Read, Seek};
5+
use std::num::NonZeroUsize;
56
use std::path::{Path, PathBuf};
67

7-
use anyhow::{bail, Result};
8+
use anyhow::Result;
89
use flate2::read::GzDecoder;
910
use log::error;
1011
use sha1_smol::{Digest, Sha1};
@@ -159,22 +160,18 @@ pub fn get_sha1_checksum<R: Read>(rdr: R) -> Result<Digest> {
159160

160161
/// Returns the SHA1 hash for the entire input, as well as each chunk of it. The
161162
/// `chunk_size` must be non-zero.
162-
pub fn get_sha1_checksums(data: &[u8], chunk_size: usize) -> Result<(Digest, Vec<Digest>)> {
163-
if chunk_size == 0 {
164-
bail!("Chunk size may not be zero.");
165-
}
166-
163+
pub fn get_sha1_checksums(data: &[u8], chunk_size: NonZeroUsize) -> (Digest, Vec<Digest>) {
167164
let mut total_sha = Sha1::new();
168165
let mut chunks = Vec::new();
169166

170-
for chunk in data.chunks(chunk_size) {
167+
for chunk in data.chunks(chunk_size.into()) {
171168
let mut chunk_sha = Sha1::new();
172169
chunk_sha.update(chunk);
173170
total_sha.update(chunk);
174171
chunks.push(chunk_sha.digest());
175172
}
176173

177-
Ok((total_sha.digest(), chunks))
174+
(total_sha.digest(), chunks)
178175
}
179176

180177
/// Checks if provided slice contains gzipped data.
@@ -245,9 +242,10 @@ mod tests {
245242

246243
#[test]
247244
fn sha1_checksums_power_of_two() {
245+
const NONZERO_16: NonZeroUsize = NonZeroUsize::new(16).unwrap();
246+
248247
let data = b"this is some binary data for the test";
249-
let (total_sha, chunks) =
250-
get_sha1_checksums(data, 16).expect("Method should not fail because 16 is not zero");
248+
let (total_sha, chunks) = get_sha1_checksums(data, NONZERO_16);
251249

252250
assert_eq!(
253251
total_sha.to_string(),
@@ -268,10 +266,11 @@ mod tests {
268266

269267
#[test]
270268
fn sha1_checksums_not_power_of_two() {
269+
const NONZERO_17: NonZeroUsize = NonZeroUsize::new(17).unwrap();
270+
271271
let data = b"this is some binary data for the test";
272272

273-
let (total_sha, chunks) =
274-
get_sha1_checksums(data, 17).expect("Method should not fail because 17 is not zero");
273+
let (total_sha, chunks) = get_sha1_checksums(data, NONZERO_17);
275274

276275
assert_eq!(
277276
total_sha.to_string(),
@@ -289,10 +288,4 @@ mod tests {
289288
]
290289
);
291290
}
292-
293-
#[test]
294-
fn sha1_checksums_zero() {
295-
let data = b"this is some binary data for the test";
296-
get_sha1_checksums(data, 0).expect_err("Method should fail because 0 is zero");
297-
}
298291
}

src/utils/proguard/upload.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ pub fn chunk_upload(
2626
org: &str,
2727
project: &str,
2828
) -> Result<()> {
29+
let chunk_size = chunk_upload_options.chunk_size;
2930
let chunked_mappings = mappings
3031
.iter()
31-
.map(|mapping| Chunked::from(mapping, chunk_upload_options.chunk_size as usize))
32-
.collect::<Result<Vec<_>>>()?;
32+
.map(|mapping| Chunked::from(mapping, chunk_size))
33+
.collect::<Vec<_>>();
3334

3435
let options =
3536
ChunkOptions::new(chunk_upload_options, org, project).with_max_wait(ASSEMBLE_POLL_TIMEOUT);

0 commit comments

Comments
 (0)