@@ -3,7 +3,6 @@ use crate::core::SourceId;
3
3
use crate :: core:: { GitReference , Package , Workspace } ;
4
4
use crate :: ops;
5
5
use crate :: sources:: path:: PathSource ;
6
- use crate :: sources:: PathEntry ;
7
6
use crate :: sources:: RegistrySource ;
8
7
use crate :: sources:: SourceConfigMap ;
9
8
use crate :: sources:: CRATES_IO_REGISTRY ;
@@ -255,17 +254,19 @@ fn sync(
255
254
_ => unreachable ! ( "not registry source: {sid}" ) ,
256
255
} ;
257
256
258
- let mut compute_file_cksums = |root| {
259
- let walkdir = WalkDir :: new ( root)
257
+ let walkdir = |root| {
258
+ WalkDir :: new ( root)
260
259
. into_iter ( )
261
260
// It is safe to skip errors,
262
261
// since we'll hit them during copying/reading later anyway.
263
262
. filter_map ( |e| e. ok ( ) )
264
263
// There should be no symlink in tarballs on crates.io,
265
264
// but might be wrong for local registries.
266
265
// Hence here be conservative and include symlinks.
267
- . filter ( |e| e. file_type ( ) . is_file ( ) || e. file_type ( ) . is_symlink ( ) ) ;
268
- for e in walkdir {
266
+ . filter ( |e| e. file_type ( ) . is_file ( ) || e. file_type ( ) . is_symlink ( ) )
267
+ } ;
268
+ let mut compute_file_cksums = |root| {
269
+ for e in walkdir ( root) {
269
270
let path = e. path ( ) ;
270
271
let relative = path. strip_prefix ( & dst) . unwrap ( ) ;
271
272
let cksum = Sha256 :: new ( )
@@ -289,11 +290,24 @@ fn sync(
289
290
. tempdir_in ( vendor_dir) ?;
290
291
let unpacked_src =
291
292
registry. unpack_package_in ( id, staging_dir. path ( ) , & vendor_this) ?;
292
- fs:: rename ( & unpacked_src, & dst) ?;
293
- compute_file_cksums ( & dst) ?;
293
+ if let Err ( e) = fs:: rename ( & unpacked_src, & dst) {
294
+ // This fallback is mainly for Windows 10 versions earlier than 1607.
295
+ // The destination of `fs::rename` can't be a diretory in older versions.
296
+ // Can be removed once the minimal supported Windows version gets bumped.
297
+ tracing:: warn!( "failed to `mv {unpacked_src:?} {dst:?}`: {e}" ) ;
298
+ let paths: Vec < _ > = walkdir ( & unpacked_src) . map ( |e| e. into_path ( ) ) . collect ( ) ;
299
+ cp_sources ( pkg, src, & paths, & dst, & mut file_cksums, & mut tmp_buf, gctx)
300
+ . with_context ( || format ! ( "failed to copy vendored sources for {id}" ) ) ?;
301
+ } else {
302
+ compute_file_cksums ( & dst) ?;
303
+ }
294
304
}
295
305
} else {
296
- let paths = PathSource :: new ( src, sid, gctx) . list_files ( pkg) ?;
306
+ let paths = PathSource :: new ( src, sid, gctx)
307
+ . list_files ( pkg) ?
308
+ . into_iter ( )
309
+ . map ( |p| p. into_path_buf ( ) )
310
+ . collect :: < Vec < _ > > ( ) ;
297
311
cp_sources ( pkg, src, & paths, & dst, & mut file_cksums, & mut tmp_buf, gctx)
298
312
. with_context ( || format ! ( "failed to copy vendored sources for {id}" ) ) ?;
299
313
}
@@ -387,14 +401,13 @@ fn sync(
387
401
fn cp_sources (
388
402
pkg : & Package ,
389
403
src : & Path ,
390
- paths : & [ PathEntry ] ,
404
+ paths : & [ PathBuf ] ,
391
405
dst : & Path ,
392
406
cksums : & mut BTreeMap < String , String > ,
393
407
tmp_buf : & mut [ u8 ] ,
394
408
gctx : & GlobalContext ,
395
409
) -> CargoResult < ( ) > {
396
410
for p in paths {
397
- let p = p. as_ref ( ) ;
398
411
let relative = p. strip_prefix ( & src) . unwrap ( ) ;
399
412
400
413
if !vendor_this ( relative) {
0 commit comments