File tree 3 files changed +29
-2
lines changed 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ pub struct Options {
13
13
flag_color : Option < String > ,
14
14
flag_frozen : bool ,
15
15
flag_locked : bool ,
16
+ flag_offline : bool ,
16
17
}
17
18
18
19
pub const USAGE : & ' static str = "
@@ -29,6 +30,8 @@ Options:
29
30
--color WHEN Coloring: auto, always, never
30
31
--frozen Require Cargo.lock and cache are up to date
31
32
--locked Require Cargo.lock is up to date
33
+ --offline Do not download crates.io registry and use
34
+ a potentially stale local copy
32
35
" ;
33
36
34
37
pub fn execute ( options : Options , config : & Config ) -> CliResult {
@@ -38,6 +41,9 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
38
41
& options. flag_color ,
39
42
options. flag_frozen ,
40
43
options. flag_locked ) ?;
44
+ if options. flag_offline {
45
+ config. disable_registry_update ( ) ;
46
+ }
41
47
let root = find_root_manifest_for_wd ( options. flag_manifest_path , config. cwd ( ) ) ?;
42
48
43
49
let ws = Workspace :: new ( & root, config) ?;
Original file line number Diff line number Diff line change @@ -60,7 +60,9 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
60
60
//
61
61
// This way if there's a problem the error gets printed before we even
62
62
// hit the index, which may not actually read this configuration.
63
- ops:: http_handle ( self . config ) ?;
63
+ if self . config . registry_update_allowed ( ) {
64
+ ops:: http_handle ( self . config ) ?;
65
+ }
64
66
65
67
// Then we actually update the index
66
68
self . index_path . create_dir ( ) ?;
@@ -69,10 +71,19 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
69
71
"the registry index" ) ?;
70
72
let path = lock. path ( ) . parent ( ) . unwrap ( ) ;
71
73
74
+ let existing_repo = git2:: Repository :: open ( path) ;
75
+ if !self . config . registry_update_allowed ( ) {
76
+ return if let Err ( e) = existing_repo {
77
+ Err ( e. into ( ) )
78
+ } else {
79
+ Ok ( ( ) )
80
+ }
81
+ }
82
+
72
83
self . config . shell ( ) . status ( "Updating" ,
73
84
format ! ( "registry `{}`" , self . source_id. url( ) ) ) ?;
74
85
75
- let repo = git2 :: Repository :: open ( path ) . or_else ( |_| {
86
+ let repo = existing_repo . or_else ( |_| {
76
87
let _ = lock. remove_siblings ( ) ;
77
88
git2:: Repository :: init ( path)
78
89
} ) ?;
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ pub struct Config {
33
33
extra_verbose : Cell < bool > ,
34
34
frozen : Cell < bool > ,
35
35
locked : Cell < bool > ,
36
+ disable_registry_update : Cell < bool > ,
36
37
}
37
38
38
39
impl Config {
@@ -50,6 +51,7 @@ impl Config {
50
51
extra_verbose : Cell :: new ( false ) ,
51
52
frozen : Cell :: new ( false ) ,
52
53
locked : Cell :: new ( false ) ,
54
+ disable_registry_update : Cell :: new ( false ) ,
53
55
}
54
56
}
55
57
@@ -377,6 +379,14 @@ impl Config {
377
379
!self . frozen . get ( ) && !self . locked . get ( )
378
380
}
379
381
382
+ pub fn registry_update_allowed ( & self ) -> bool {
383
+ !self . disable_registry_update . get ( )
384
+ }
385
+
386
+ pub fn disable_registry_update ( & self ) {
387
+ self . disable_registry_update . set ( true )
388
+ }
389
+
380
390
fn load_values ( & self ) -> CargoResult < HashMap < String , ConfigValue > > {
381
391
let mut cfg = CV :: Table ( HashMap :: new ( ) , PathBuf :: from ( "." ) ) ;
382
392
You can’t perform that action at this time.
0 commit comments