Skip to content

Commit 736de0d

Browse files
committed
Revert "Slightly optimize cargo vendor"
This reverts commit 01f1c01.
1 parent 8830023 commit 736de0d

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

src/cargo/ops/vendor.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use serde::Serialize;
99
use std::collections::HashSet;
1010
use std::collections::{BTreeMap, BTreeSet, HashMap};
1111
use std::fs;
12-
use std::fs::File;
13-
use std::io::{Read, Write};
1412
use std::path::{Path, PathBuf};
1513

1614
pub struct VendorOptions<'a> {
@@ -184,7 +182,6 @@ fn sync(
184182
}
185183

186184
let mut sources = BTreeSet::new();
187-
let mut tmp_buf = [0; 64 * 1024];
188185
for (id, pkg) in ids.iter() {
189186
// Next up, copy it to the vendor directory
190187
let src = pkg
@@ -219,7 +216,7 @@ fn sync(
219216
let pathsource = PathSource::new(src, id.source_id(), config);
220217
let paths = pathsource.list_files(pkg)?;
221218
let mut map = BTreeMap::new();
222-
cp_sources(src, &paths, &dst, &mut map, &mut tmp_buf)
219+
cp_sources(src, &paths, &dst, &mut map)
223220
.chain_err(|| format!("failed to copy over vendored sources for: {}", id))?;
224221

225222
// Finally, emit the metadata about this package
@@ -302,7 +299,6 @@ fn cp_sources(
302299
paths: &[PathBuf],
303300
dst: &Path,
304301
cksums: &mut BTreeMap<String, String>,
305-
tmp_buf: &mut [u8],
306302
) -> CargoResult<()> {
307303
for p in paths {
308304
let relative = p.strip_prefix(&src).unwrap();
@@ -338,27 +334,9 @@ fn cp_sources(
338334

339335
paths::create_dir_all(dst.parent().unwrap())?;
340336

341-
let cksum = copy_and_checksum(&p, &dst, tmp_buf)?;
337+
paths::copy(&p, &dst)?;
338+
let cksum = Sha256::new().update_path(dst)?.finish_hex();
342339
cksums.insert(relative.to_str().unwrap().replace("\\", "/"), cksum);
343340
}
344341
Ok(())
345342
}
346-
347-
fn copy_and_checksum(src_path: &Path, dst_path: &Path, buf: &mut [u8]) -> CargoResult<String> {
348-
let mut src = File::open(src_path).chain_err(|| format!("failed to open {:?}", src_path))?;
349-
let mut dst =
350-
File::create(dst_path).chain_err(|| format!("failed to create {:?}", dst_path))?;
351-
let mut cksum = Sha256::new();
352-
loop {
353-
let n = src
354-
.read(buf)
355-
.chain_err(|| format!("failed to read from {:?}", src_path))?;
356-
if n == 0 {
357-
break Ok(cksum.finish_hex());
358-
}
359-
let data = &buf[..n];
360-
cksum.update(data);
361-
dst.write_all(data)
362-
.chain_err(|| format!("failed to write to {:?}", dst_path))?;
363-
}
364-
}

0 commit comments

Comments
 (0)