Skip to content

Commit 1b65526

Browse files
lcianclaude
andauthored
ref(snapshots): Use file-based upload for objectstore puts (#3185)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1a0e6ef commit 1b65526

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

src/commands/build/snapshots.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::collections::HashMap;
2-
use std::fs::{self, File};
2+
use std::fs::File;
33
use std::io::BufReader;
44
use std::path::{Path, PathBuf};
55
use std::str::FromStr as _;
@@ -212,11 +212,24 @@ fn validate_image_sizes(images: &[ImageInfo]) -> Result<()> {
212212
Ok(())
213213
}
214214

215-
fn compute_sha256_hash(data: &[u8]) -> String {
215+
fn compute_sha256_hash(path: &Path) -> Result<String> {
216+
use std::io::Read as _;
217+
218+
let mut file = std::fs::File::open(path)
219+
.with_context(|| format!("Failed to open image for hashing: {}", path.display()))?;
216220
let mut hasher = Sha256::new();
217-
hasher.update(data);
221+
let mut buffer = [0u8; 8192];
222+
loop {
223+
let bytes_read = file
224+
.read(&mut buffer)
225+
.with_context(|| format!("Failed to read image for hashing: {}", path.display()))?;
226+
if bytes_read == 0 {
227+
break;
228+
}
229+
hasher.update(&buffer[..bytes_read]);
230+
}
218231
let result = hasher.finalize();
219-
format!("{result:x}")
232+
Ok(format!("{result:x}"))
220233
}
221234

222235
fn is_hidden(root: &Path, path: &Path) -> bool {
@@ -297,15 +310,18 @@ fn upload_images(
297310
for image in images {
298311
debug!("Processing image: {}", image.path.display());
299312

300-
let contents = fs::read(&image.path)
301-
.with_context(|| format!("Failed to read image: {}", image.path.display()))?;
302-
let hash = compute_sha256_hash(&contents);
313+
let hash = compute_sha256_hash(&image.path)?;
314+
let file = runtime
315+
.block_on(tokio::fs::File::open(&image.path))
316+
.with_context(|| {
317+
format!("Failed to open image for upload: {}", image.path.display())
318+
})?;
303319

304320
info!("Queueing {} as {hash}", image.relative_path.display());
305321

306322
many_builder = many_builder.push(
307323
session
308-
.put(contents)
324+
.put_file(file)
309325
.key(&hash)
310326
.expiration_policy(expiration),
311327
);

0 commit comments

Comments
 (0)