-
Notifications
You must be signed in to change notification settings - Fork 884
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for machine wide installs: fallback-settings file
This provides a way for snaps, distro packages and other such installs to set the default-toolchain for users that have not gone through the rustup-init one-time set of questions. /etc/rustup/settings.toml can more now just provide a default toolchain for users of rustup on the machine. More keys will be supported as needed. No equivalent file is defined for Windows OS machines at this time.
- Loading branch information
1 parent
6de2f76
commit f6315b4
Showing
7 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::errors::*; | ||
use crate::utils::utils; | ||
use serde::Deserialize; | ||
use std::error::Error; | ||
use std::io; | ||
use std::path::Path; | ||
|
||
#[derive(Clone, Debug, Deserialize, PartialEq)] | ||
pub struct FallbackSettings { | ||
pub default_toolchain: Option<String>, | ||
} | ||
|
||
impl Default for FallbackSettings { | ||
fn default() -> Self { | ||
Self { | ||
default_toolchain: None, | ||
} | ||
} | ||
} | ||
|
||
impl FallbackSettings { | ||
pub fn new<P: AsRef<Path>>(path: P) -> Result<Option<Self>> { | ||
// Users cannot fix issues with missing/unreadable/invalid centralised files, but logging isn't setup early so | ||
// we can't simply trap all errors and log diagnostics. Ideally we would, and then separate these into different | ||
// sorts of issues, logging messages about errors that should be fixed. Instead we trap some conservative errors | ||
// that hopefully won't lead to too many tickets. | ||
match utils::read_file("fallback settings", path.as_ref()) { | ||
Err(e @ Error(ErrorKind::ReadingFile { .. }, _)) => { | ||
let io_err = e.source().unwrap().downcast_ref::<io::Error>().unwrap(); | ||
match io_err.kind() { | ||
io::ErrorKind::NotFound | io::ErrorKind::PermissionDenied => Ok(None), | ||
_ => Err(e.into()), | ||
} | ||
} | ||
Err(e) => Err(e), | ||
Ok(file_contents) => Ok(Some( | ||
toml::from_str(&file_contents).map_err(ErrorKind::ParsingFallbackSettings)?, | ||
)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters