@@ -12,13 +12,13 @@ use rustup_dist::{temp, dist};
12
12
use rustup_utils:: utils;
13
13
use toolchain:: { Toolchain , UpdateStatus } ;
14
14
use telemetry_analysis:: * ;
15
- use settings:: { TelemetryMode , SettingsFile , DEFAULT_METADATA_VERSION } ;
15
+ use settings:: { TelemetryMode , SettingsFile , Settings , DEFAULT_METADATA_VERSION } ;
16
16
17
17
#[ derive( Debug ) ]
18
18
pub enum OverrideReason {
19
19
Environment ,
20
20
OverrideDB ( PathBuf ) ,
21
- VersionFile ( PathBuf ) ,
21
+ ToolchainFile ( PathBuf ) ,
22
22
}
23
23
24
24
impl Display for OverrideReason {
@@ -28,7 +28,7 @@ impl Display for OverrideReason {
28
28
OverrideReason :: OverrideDB ( ref path) => {
29
29
write ! ( f, "directory override for '{}'" , path. display( ) )
30
30
}
31
- OverrideReason :: VersionFile ( ref path) => {
31
+ OverrideReason :: ToolchainFile ( ref path) => {
32
32
write ! ( f, "overridden by '{}'" , path. display( ) )
33
33
}
34
34
}
@@ -232,20 +232,14 @@ impl Cfg {
232
232
override_ = Some ( ( name. to_string ( ) , OverrideReason :: Environment ) ) ;
233
233
}
234
234
235
- // Then look in the override database
235
+ // Then walk up the directory tree from 'path' looking for either the
236
+ // directory in override database, or a `rust-toolchain` file.
236
237
if override_. is_none ( ) {
237
- try!( self . settings_file . with ( |s| {
238
- let name = s. find_override ( path, self . notify_handler . as_ref ( ) ) ;
239
- override_ = name. map ( |( name, reason_path) | ( name, OverrideReason :: OverrideDB ( reason_path) ) ) ;
238
+ self . settings_file . with ( |s| {
239
+ override_ = self . find_override_from_dir_walk ( path, s) ?;
240
240
241
241
Ok ( ( ) )
242
- } ) ) ;
243
- }
244
-
245
- // Then check the explicit version file
246
- if override_. is_none ( ) {
247
- let name_path = self . find_override_version_file ( path) ?;
248
- override_ = name_path. map ( |( name, path) | ( name, OverrideReason :: VersionFile ( path) ) ) ;
242
+ } ) ?;
249
243
}
250
244
251
245
if let Some ( ( name, reason) ) = override_ {
@@ -260,8 +254,8 @@ impl Cfg {
260
254
OverrideReason :: OverrideDB ( ref path) => {
261
255
format ! ( "the directory override for '{}' specifies an uninstalled toolchain" , path. display( ) )
262
256
}
263
- OverrideReason :: VersionFile ( ref path) => {
264
- format ! ( "the version file at '{}' specifies an uninstalled toolchain" , path. display( ) )
257
+ OverrideReason :: ToolchainFile ( ref path) => {
258
+ format ! ( "the toolchain file at '{}' specifies an uninstalled toolchain" , path. display( ) )
265
259
}
266
260
} ;
267
261
@@ -286,25 +280,36 @@ impl Cfg {
286
280
}
287
281
}
288
282
289
- /// Starting in path walk up the tree looking for .rust-version
290
- fn find_override_version_file ( & self , path : & Path ) -> Result < Option < ( String , PathBuf ) > > {
291
- let mut path = Some ( path) ;
283
+ fn find_override_from_dir_walk ( & self , dir : & Path , settings : & Settings )
284
+ -> Result < Option < ( String , OverrideReason ) > >
285
+ {
286
+ let notify = self . notify_handler . as_ref ( ) ;
287
+ let dir = utils:: canonicalize_path ( dir, & |n| notify ( n. into ( ) ) ) ;
288
+ let mut dir = Some ( & * dir) ;
289
+
290
+ while let Some ( d) = dir {
291
+ // First check the override database
292
+ if let Some ( name) = settings. dir_override ( d, notify) {
293
+ let reason = OverrideReason :: OverrideDB ( d. to_owned ( ) ) ;
294
+ return Ok ( Some ( ( name, reason) ) ) ;
295
+ }
292
296
293
- while let Some ( p ) = path {
294
- let version_file = p . join ( ". rust-version " ) ;
295
- if let Ok ( s) = utils:: read_file ( "version file" , & version_file ) {
297
+ // Then look for 'rust-toolchain'
298
+ let toolchain_file = d . join ( "rust-toolchain " ) ;
299
+ if let Ok ( s) = utils:: read_file ( "toolchain file" , & toolchain_file ) {
296
300
if let Some ( s) = s. lines ( ) . next ( ) {
297
301
let toolchain_name = s. trim ( ) ;
298
302
dist:: validate_channel_name ( & toolchain_name)
299
303
. chain_err ( || format ! ( "invalid channel name '{}' in '{}'" ,
300
304
toolchain_name,
301
- version_file . display( ) ) ) ?;
305
+ toolchain_file . display( ) ) ) ?;
302
306
303
- return Ok ( Some ( ( toolchain_name. to_string ( ) , version_file) ) ) ;
307
+ let reason = OverrideReason :: ToolchainFile ( toolchain_file) ;
308
+ return Ok ( Some ( ( toolchain_name. to_string ( ) , reason) ) ) ;
304
309
}
305
310
}
306
311
307
- path = p . parent ( ) ;
312
+ dir = d . parent ( ) ;
308
313
}
309
314
310
315
Ok ( None )
0 commit comments