@@ -195,6 +195,8 @@ pub enum IndexSummary {
195
195
Candidate ( Summary ) ,
196
196
/// Yanked within its registry
197
197
Yanked ( Summary ) ,
198
+ /// Not available as we are offline and create is not downloaded yet
199
+ Offline ( Summary ) ,
198
200
/// From a newer schema version and is likely incomplete or inaccurate
199
201
Unsupported ( Summary , u32 ) ,
200
202
}
@@ -205,6 +207,7 @@ impl IndexSummary {
205
207
match self {
206
208
IndexSummary :: Candidate ( sum)
207
209
| IndexSummary :: Yanked ( sum)
210
+ | IndexSummary :: Offline ( sum)
208
211
| IndexSummary :: Unsupported ( sum, _) => sum,
209
212
}
210
213
}
@@ -214,6 +217,7 @@ impl IndexSummary {
214
217
match self {
215
218
IndexSummary :: Candidate ( sum)
216
219
| IndexSummary :: Yanked ( sum)
220
+ | IndexSummary :: Offline ( sum)
217
221
| IndexSummary :: Unsupported ( sum, _) => sum. package_id ( ) ,
218
222
}
219
223
}
@@ -471,6 +475,9 @@ impl<'cfg> RegistryIndex<'cfg> {
471
475
) ;
472
476
None
473
477
}
478
+ Ok ( IndexSummary :: Offline ( _) ) => {
479
+ unreachable ! ( "We do not check for off-line until later" )
480
+ }
474
481
Err ( e) => {
475
482
info ! ( "failed to parse `{}` registry package: {}" , name, e) ;
476
483
None
@@ -555,14 +562,35 @@ impl<'cfg> RegistryIndex<'cfg> {
555
562
// then cargo will fail to download and an error message
556
563
// indicating that the required dependency is unavailable while
557
564
// offline will be displayed.
558
- if ready ! ( self . query_inner_with_online( name, req, load, yanked_whitelist, f, false ) ?)
559
- > 0
560
- {
565
+ let mut called = false ;
566
+ let callback = & mut |s : IndexSummary | {
567
+ if !matches ! ( & s, & IndexSummary :: Offline ( _) ) {
568
+ called = true ;
569
+ f ( s. as_summary ( ) . clone ( ) ) ;
570
+ }
571
+ } ;
572
+ ready ! ( self . query_inner_with_online(
573
+ name,
574
+ req,
575
+ load,
576
+ yanked_whitelist,
577
+ callback,
578
+ false
579
+ ) ?) ;
580
+ if called {
561
581
return Poll :: Ready ( Ok ( ( ) ) ) ;
562
582
}
563
583
}
564
- self . query_inner_with_online ( name, req, load, yanked_whitelist, f, true )
565
- . map_ok ( |_| ( ) )
584
+ self . query_inner_with_online (
585
+ name,
586
+ req,
587
+ load,
588
+ yanked_whitelist,
589
+ & mut |s| {
590
+ f ( s. as_summary ( ) . clone ( ) ) ;
591
+ } ,
592
+ true ,
593
+ )
566
594
}
567
595
568
596
/// Inner implementation of [`Self::query_inner`]. Returns the number of
@@ -575,9 +603,9 @@ impl<'cfg> RegistryIndex<'cfg> {
575
603
req : & OptVersionReq ,
576
604
load : & mut dyn RegistryData ,
577
605
yanked_whitelist : & HashSet < PackageId > ,
578
- f : & mut dyn FnMut ( Summary ) ,
606
+ f : & mut dyn FnMut ( IndexSummary ) ,
579
607
online : bool ,
580
- ) -> Poll < CargoResult < usize > > {
608
+ ) -> Poll < CargoResult < ( ) > > {
581
609
let source_id = self . source_id ;
582
610
583
611
let summaries = ready ! ( self . summaries( name, req, load) ) ?;
@@ -593,14 +621,19 @@ impl<'cfg> RegistryIndex<'cfg> {
593
621
// does not satisfy the requirements, then resolution will
594
622
// fail. Unfortunately, whether or not something is optional
595
623
// is not known here.
596
- . filter ( |s| ( online || load. is_crate_downloaded ( s. package_id ( ) ) ) )
624
+ . map ( |s| {
625
+ if online || load. is_crate_downloaded ( s. package_id ( ) ) {
626
+ s. clone ( )
627
+ } else {
628
+ IndexSummary :: Offline ( s. as_summary ( ) . clone ( ) )
629
+ }
630
+ } )
597
631
// Next filter out all yanked packages. Some yanked packages may
598
632
// leak through if they're in a whitelist (aka if they were
599
633
// previously in `Cargo.lock`
600
634
. filter ( |s| {
601
635
!matches ! ( s, IndexSummary :: Yanked ( _) ) || yanked_whitelist. contains ( & s. package_id ( ) )
602
- } )
603
- . map ( |s| s. clone ( ) ) ;
636
+ } ) ;
604
637
605
638
// Handle `cargo update --precise` here.
606
639
let precise = source_id. precise_registry_version ( name. as_str ( ) ) ;
@@ -631,12 +664,8 @@ impl<'cfg> RegistryIndex<'cfg> {
631
664
None => true ,
632
665
} ) ;
633
666
634
- let mut count = 0 ;
635
- for summary in summaries {
636
- f ( summary. as_summary ( ) . clone ( ) ) ;
637
- count += 1 ;
638
- }
639
- Poll :: Ready ( Ok ( count) )
667
+ summaries. for_each ( f) ;
668
+ Poll :: Ready ( Ok ( ( ) ) )
640
669
}
641
670
642
671
/// Looks into the summaries to check if a package has been yanked.
0 commit comments