@@ -346,19 +346,18 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
346
346
use std:: collections:: btree_map:: Entry ;
347
347
match self . downloads . eager . entry ( path. to_path_buf ( ) ) {
348
348
Entry :: Occupied ( mut o) => {
349
- let o = o. get_mut ( ) ;
350
- if & o. primary . req != req {
351
- o. others . insert ( req. clone ( ) ) ;
352
- }
349
+ o. get_mut ( ) . reqs . insert ( req. clone ( ) ) ;
353
350
}
354
351
Entry :: Vacant ( v) => {
355
- v. insert ( MultiVersionFetched {
356
- primary : Fetched {
357
- path : path. to_path_buf ( ) ,
358
- name,
359
- req : req. clone ( ) ,
360
- } ,
361
- others : HashSet :: new ( ) ,
352
+ if self . prefetched . contains ( path) {
353
+ debug ! ( "yielding already-prefetched {}" , name) ;
354
+ }
355
+ let mut reqs = HashSet :: new ( ) ;
356
+ reqs. insert ( req. clone ( ) ) ;
357
+ v. insert ( Fetched {
358
+ path : path. to_path_buf ( ) ,
359
+ name,
360
+ reqs,
362
361
} ) ;
363
362
}
364
363
}
@@ -399,14 +398,10 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
399
398
. pending
400
399
. get_mut ( token)
401
400
. expect ( "invalid token" ) ;
402
- if & dl. req != req {
403
- dl. additional_reqs . insert ( req. clone ( ) ) ;
404
- }
401
+ dl. reqs . insert ( req. clone ( ) ) ;
405
402
return Ok ( ( ) ) ;
406
403
} else if let Some ( f) = self . downloads . eager . get_mut ( path) {
407
- if & f. primary . req != req {
408
- f. others . insert ( req. clone ( ) ) ;
409
- }
404
+ f. reqs . insert ( req. clone ( ) ) ;
410
405
return Ok ( ( ) ) ;
411
406
}
412
407
@@ -459,13 +454,14 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
459
454
None ,
460
455
"path queued for download more than once"
461
456
) ;
457
+ let mut reqs = HashSet :: new ( ) ;
458
+ reqs. insert ( req. clone ( ) ) ;
462
459
let dl = Download {
463
460
token,
464
461
data : RefCell :: new ( Vec :: new ( ) ) ,
465
462
path : path. to_path_buf ( ) ,
466
463
name,
467
- req : req. clone ( ) ,
468
- additional_reqs : HashSet :: new ( ) ,
464
+ reqs,
469
465
etag : RefCell :: new ( None ) ,
470
466
last_modified : RefCell :: new ( None ) ,
471
467
} ;
@@ -540,26 +536,8 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
540
536
//
541
537
// TODO: Use the nightly BTreeMap::pop_first when stable.
542
538
if let Some ( path) = self . downloads . eager . keys ( ) . next ( ) . cloned ( ) {
543
- use std:: collections:: btree_map:: Entry ;
544
- let mut fetched = if let Entry :: Occupied ( o) = self . downloads . eager . entry ( path) {
545
- o
546
- } else {
547
- unreachable ! ( ) ;
548
- } ;
549
-
550
- return if let Some ( req) = fetched. get ( ) . others . iter ( ) . next ( ) . cloned ( ) {
551
- let fetched = fetched. get_mut ( ) ;
552
- fetched. others . remove ( & req) ;
553
- let ret = Ok ( Some ( Fetched {
554
- path : fetched. primary . path . clone ( ) ,
555
- name : fetched. primary . name ,
556
- req,
557
- } ) ) ;
558
- ret
559
- } else {
560
- let fetched = fetched. remove ( ) ;
561
- Ok ( Some ( fetched. primary ) )
562
- } ;
539
+ let fetched = self . downloads . eager . remove ( & path) . unwrap ( ) ;
540
+ return Ok ( Some ( fetched) ) ;
563
541
}
564
542
565
543
// We don't have any fetched results immediately ready to be yielded,
@@ -606,31 +584,28 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
606
584
let mut handle = self . prefetch . remove ( handle) ?;
607
585
self . downloads . pending_ids . remove ( & dl. path ) ;
608
586
609
- let fetched = MultiVersionFetched {
610
- primary : Fetched {
611
- path : dl. path ,
612
- name : dl. name ,
613
- req : dl. req ,
614
- } ,
615
- others : dl. additional_reqs ,
587
+ let fetched = Fetched {
588
+ path : dl. path ,
589
+ name : dl. name ,
590
+ reqs : dl. reqs ,
616
591
} ;
617
592
assert ! (
618
- self . prefetched. insert( fetched. primary . path. clone( ) ) ,
593
+ self . prefetched. insert( fetched. path. clone( ) ) ,
619
594
"downloaded the same path twice during prefetching"
620
595
) ;
621
596
622
597
let code = handle. response_code ( ) ?;
623
598
debug ! (
624
599
"index file for {} downloaded with status code {}" ,
625
- fetched. primary . name,
600
+ fetched. name,
626
601
handle. response_code( ) ?
627
602
) ;
628
603
match code {
629
604
200 => {
630
605
// We got data back, hooray!
631
606
// Let's update the index file.
632
607
let path = self . config . assert_package_cache_locked ( & self . index_path ) ;
633
- let pkg = path. join ( & fetched. primary . path ) ;
608
+ let pkg = path. join ( & fetched. path ) ;
634
609
paths:: create_dir_all ( pkg. parent ( ) . expect ( "pkg is a file" ) ) ?;
635
610
let mut file = paths:: create ( pkg) ?;
636
611
file. write_all ( dl. etag . into_inner ( ) . as_deref ( ) . unwrap_or ( "\n " ) . as_bytes ( ) ) ?;
@@ -647,7 +622,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
647
622
assert ! (
648
623
self . downloads
649
624
. eager
650
- . insert( fetched. primary . path. clone( ) , fetched)
625
+ . insert( fetched. path. clone( ) , fetched)
651
626
. is_none( ) ,
652
627
"download finished for already-finished path"
653
628
) ;
@@ -659,7 +634,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
659
634
assert ! (
660
635
self . downloads
661
636
. eager
662
- . insert( fetched. primary . path. clone( ) , fetched)
637
+ . insert( fetched. path. clone( ) , fetched)
663
638
. is_none( ) ,
664
639
"download finished for already-finished path"
665
640
) ;
@@ -1502,11 +1477,6 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
1502
1477
}
1503
1478
}
1504
1479
1505
- struct MultiVersionFetched {
1506
- primary : Fetched ,
1507
- others : HashSet < semver:: VersionReq > ,
1508
- }
1509
-
1510
1480
// NOTE: what follows is lifted from src/cargo/core/package.rs and tweaked
1511
1481
1512
1482
/// Helper for downloading crates.
@@ -1526,7 +1496,7 @@ pub struct Downloads {
1526
1496
results : Vec < ( usize , Result < ( ) , curl:: Error > ) > ,
1527
1497
/// Prefetch requests that we already have a response to.
1528
1498
/// NOTE: Should this maybe be some kind of heap?
1529
- eager : BTreeMap < PathBuf , MultiVersionFetched > ,
1499
+ eager : BTreeMap < PathBuf , Fetched > ,
1530
1500
/// The next ID to use for creating a token (see `Download::token`).
1531
1501
next : usize ,
1532
1502
}
@@ -1543,10 +1513,8 @@ struct Download {
1543
1513
name : InternedString ,
1544
1514
1545
1515
/// The version requirements for the dependency line that triggered this fetch.
1546
- req : semver:: VersionReq ,
1547
-
1548
- /// Additional version requirements for same package.
1549
- additional_reqs : HashSet < semver:: VersionReq > ,
1516
+ // NOTE: with https://github.com/steveklabnik/semver/issues/170 the HashSet is unnecessary
1517
+ reqs : HashSet < semver:: VersionReq > ,
1550
1518
1551
1519
/// Actual downloaded data, updated throughout the lifetime of this download.
1552
1520
data : RefCell < Vec < u8 > > ,
0 commit comments