1
- use std:: { cmp, env} ;
2
1
use std:: collections:: BTreeMap ;
3
2
use std:: fs:: { self , File } ;
4
3
use std:: iter:: repeat;
5
4
use std:: time:: Duration ;
5
+ use std:: { cmp, env} ;
6
6
7
7
use curl:: easy:: { Easy , SslOpt } ;
8
8
use git2;
9
9
use registry:: { NewCrate , NewCrateDependency , Registry } ;
10
10
11
11
use url:: percent_encoding:: { percent_encode, QUERY_ENCODE_SET } ;
12
12
13
- use version;
14
- use core:: source:: Source ;
15
- use core:: { Package , SourceId , Workspace } ;
16
13
use core:: dependency:: Kind ;
17
14
use core:: manifest:: ManifestMetadata ;
15
+ use core:: source:: Source ;
16
+ use core:: { Package , SourceId , Workspace } ;
18
17
use ops;
19
- use sources:: RegistrySource ;
18
+ use sources:: { RegistrySource , SourceConfigMap } ;
20
19
use util:: config:: { self , Config } ;
21
- use util:: paths;
22
- use util:: ToUrl ;
23
20
use util:: errors:: { CargoResult , CargoResultExt } ;
24
21
use util:: important_paths:: find_root_manifest_for_wd;
22
+ use util:: paths;
23
+ use util:: ToUrl ;
24
+ use version;
25
25
26
26
pub struct RegistryConfig {
27
27
pub index : Option < String > ,
@@ -311,11 +311,7 @@ pub fn registry(
311
311
index : index_config,
312
312
} = registry_configuration ( config, registry. clone ( ) ) ?;
313
313
let token = token. or ( token_config) ;
314
- let sid = match ( index_config, index, registry) {
315
- ( _, _, Some ( registry) ) => SourceId :: alt_registry ( config, & registry) ?,
316
- ( Some ( index) , _, _) | ( None , Some ( index) , _) => SourceId :: for_registry ( & index. to_url ( ) ?) ?,
317
- ( None , None , _) => SourceId :: crates_io ( config) ?,
318
- } ;
314
+ let sid = get_source_id ( config, index_config. or ( index) , registry) ?;
319
315
let api_host = {
320
316
let mut src = RegistrySource :: remote ( & sid, config) ;
321
317
src. update ( )
@@ -354,10 +350,11 @@ pub fn needs_custom_http_transport(config: &Config) -> CargoResult<bool> {
354
350
let check_revoke = config. get_bool ( "http.check-revoke" ) ?;
355
351
let user_agent = config. get_string ( "http.user-agent" ) ?;
356
352
357
- Ok (
358
- proxy_exists || timeout. is_some ( ) || cainfo. is_some ( ) || check_revoke. is_some ( )
359
- || user_agent. is_some ( ) ,
360
- )
353
+ Ok ( proxy_exists
354
+ || timeout. is_some ( )
355
+ || cainfo. is_some ( )
356
+ || check_revoke. is_some ( )
357
+ || user_agent. is_some ( ) )
361
358
}
362
359
363
360
/// Configure a libcurl http handle with the defaults options for Cargo
@@ -553,6 +550,22 @@ pub fn yank(
553
550
Ok ( ( ) )
554
551
}
555
552
553
+ fn get_source_id (
554
+ config : & Config ,
555
+ index : Option < String > ,
556
+ reg : Option < String > ,
557
+ ) -> CargoResult < SourceId > {
558
+ match ( reg, index) {
559
+ ( Some ( r) , _) => SourceId :: alt_registry ( config, & r) ,
560
+ ( _, Some ( i) ) => SourceId :: for_registry ( & i. to_url ( ) ?) ,
561
+ _ => {
562
+ let map = SourceConfigMap :: new ( config) ?;
563
+ let src = map. load ( & SourceId :: crates_io ( config) ?) ?;
564
+ Ok ( src. replaced_source_id ( ) . clone ( ) )
565
+ }
566
+ }
567
+ }
568
+
556
569
pub fn search (
557
570
query : & str ,
558
571
config : & Config ,
@@ -572,7 +585,22 @@ pub fn search(
572
585
prefix
573
586
}
574
587
575
- let ( mut registry, _) = registry ( config, None , index, reg) ?;
588
+ let sid = get_source_id ( config, index, reg) ?;
589
+
590
+ let mut regsrc = RegistrySource :: remote ( & sid, config) ;
591
+ let cfg = match regsrc. config ( ) {
592
+ Ok ( c) => c,
593
+ Err ( _) => {
594
+ regsrc
595
+ . update ( )
596
+ . chain_err ( || format ! ( "failed to update {}" , & sid) ) ?;
597
+ regsrc. config ( ) ?
598
+ }
599
+ } ;
600
+
601
+ let api_host = cfg. unwrap ( ) . api . unwrap ( ) ;
602
+ let handle = http_handle ( config) ?;
603
+ let mut registry = Registry :: new_handle ( api_host, None , handle) ;
576
604
let ( crates, total_crates) = registry
577
605
. search ( query, limit)
578
606
. chain_err ( || "failed to retrieve search results from the registry" ) ?;
0 commit comments