@@ -9,8 +9,6 @@ use serde::Serialize;
9
9
use std:: collections:: HashSet ;
10
10
use std:: collections:: { BTreeMap , BTreeSet , HashMap } ;
11
11
use std:: fs;
12
- use std:: fs:: File ;
13
- use std:: io:: { Read , Write } ;
14
12
use std:: path:: { Path , PathBuf } ;
15
13
16
14
pub struct VendorOptions < ' a > {
@@ -184,7 +182,6 @@ fn sync(
184
182
}
185
183
186
184
let mut sources = BTreeSet :: new ( ) ;
187
- let mut tmp_buf = [ 0 ; 64 * 1024 ] ;
188
185
for ( id, pkg) in ids. iter ( ) {
189
186
// Next up, copy it to the vendor directory
190
187
let src = pkg
@@ -219,7 +216,7 @@ fn sync(
219
216
let pathsource = PathSource :: new ( src, id. source_id ( ) , config) ;
220
217
let paths = pathsource. list_files ( pkg) ?;
221
218
let mut map = BTreeMap :: new ( ) ;
222
- cp_sources ( src, & paths, & dst, & mut map, & mut tmp_buf )
219
+ cp_sources ( src, & paths, & dst, & mut map)
223
220
. chain_err ( || format ! ( "failed to copy over vendored sources for: {}" , id) ) ?;
224
221
225
222
// Finally, emit the metadata about this package
@@ -302,7 +299,6 @@ fn cp_sources(
302
299
paths : & [ PathBuf ] ,
303
300
dst : & Path ,
304
301
cksums : & mut BTreeMap < String , String > ,
305
- tmp_buf : & mut [ u8 ] ,
306
302
) -> CargoResult < ( ) > {
307
303
for p in paths {
308
304
let relative = p. strip_prefix ( & src) . unwrap ( ) ;
@@ -338,27 +334,9 @@ fn cp_sources(
338
334
339
335
paths:: create_dir_all ( dst. parent ( ) . unwrap ( ) ) ?;
340
336
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 ( ) ;
342
339
cksums. insert ( relative. to_str ( ) . unwrap ( ) . replace ( "\\ " , "/" ) , cksum) ;
343
340
}
344
341
Ok ( ( ) )
345
342
}
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