From b503c043465084e920d64473bd4d041207abe0d7 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 3 Jun 2016 23:30:14 +0000 Subject: [PATCH] Use Unix line endings --- .gitattributes | 5 +- src/rustup/settings.rs | 494 ++++++++++++++++++++--------------------- www/fonts/OFL.txt | 184 +++++++-------- 3 files changed, 343 insertions(+), 340 deletions(-) diff --git a/.gitattributes b/.gitattributes index 6313b56c57..c531d7a5c2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,4 @@ -* text=auto eol=lf +*.rs text eol=lf +*.lock text eol=lf +*.txt text eol=lf +*.toml text eol=lf \ No newline at end of file diff --git a/src/rustup/settings.rs b/src/rustup/settings.rs index 5398043d57..3f847acbe0 100644 --- a/src/rustup/settings.rs +++ b/src/rustup/settings.rs @@ -1,247 +1,247 @@ -use errors::*; -use notifications::*; -use toml_utils::*; -use utils; -use toml; -use std::collections::BTreeMap; -use std::path::{Path, PathBuf}; -use std::cell::RefCell; -use std::str::FromStr; - -pub const SUPPORTED_METADATA_VERSIONS: [&'static str; 2] = ["2", "12"]; -pub const DEFAULT_METADATA_VERSION: &'static str = "12"; - - -#[derive(Clone, Debug, PartialEq)] -pub struct SettingsFile { - path: PathBuf, - cache: RefCell> -} - -impl SettingsFile { - pub fn new(path: PathBuf) -> Self { - SettingsFile { - path: path, - cache: RefCell::new(None) - } - } - fn write_settings(&self) -> Result<()> { - let s = self.cache.borrow().as_ref().unwrap().clone(); - try!(utils::write_file("settings", &self.path, &s.stringify())); - Ok(()) - } - fn read_settings(&self) -> Result<()> { - let mut needs_save = false; - { - let mut b = self.cache.borrow_mut(); - if b.is_none() { - *b = Some(if utils::is_file(&self.path) { - let content = try!(utils::read_file("settings", &self.path)); - try!(Settings::parse(&content)) - } else { - needs_save = true; - Default::default() - }); - } - } - if needs_save { - try!(self.write_settings()); - } - Ok(()) - } - pub fn with Result>(&self, f: F) -> Result { - try!(self.read_settings()); - - // Settings can no longer be None so it's OK to unwrap - f(self.cache.borrow().as_ref().unwrap()) - } - pub fn with_mut Result>(&self, f: F) -> Result { - try!(self.read_settings()); - - // Settings can no longer be None so it's OK to unwrap - let result = { - try!(f(self.cache.borrow_mut().as_mut().unwrap())) - }; - try!(self.write_settings()); - Ok(result) - } - pub fn maybe_upgrade_from_legacy(&self, multirust_dir: &Path) -> Result<()> { - // Data locations - let legacy_version_file = multirust_dir.join("version"); - if utils::is_file(&legacy_version_file) { - fn split_override(s: &str, separator: char) -> Option<(T, T)> { - s.find(separator).and_then(|index| { - match (T::from_str(&s[..index]), T::from_str(&s[index + 1..])) { - (Ok(l), Ok(r)) => Some((l, r)), - _ => None - } - }) - } - - let override_db = multirust_dir.join("overrides"); - let default_file = multirust_dir.join("default"); - let telemetry_file = multirust_dir.join("telemetry-on"); - // Legacy upgrade - try!(self.with_mut(|s| { - s.version = try!(utils::read_file("version", &legacy_version_file)) - .trim().to_owned(); - - if utils::is_file(&default_file) { - s.default_toolchain = Some(try!(utils::read_file("default", &default_file)) - .trim().to_owned()); - } - if utils::is_file(&override_db) { - let overrides = try!(utils::read_file("overrides", &override_db)); - for o in overrides.lines() { - if let Some((k, v)) = split_override(o, ';') { - s.overrides.insert(k, v); - } - } - } - if utils::is_file(&telemetry_file) { - s.telemetry = TelemetryMode::On; - } - Ok(()) - })); - - // Failure to delete these is not a fatal error - let _ = utils::remove_file("version", &legacy_version_file); - let _ = utils::remove_file("default", &default_file); - let _ = utils::remove_file("overrides", &override_db); - let _ = utils::remove_file("telemetry", &telemetry_file); - } - Ok(()) - } -} - - -#[derive(Copy, Clone, Debug, PartialEq)] -pub enum TelemetryMode { - On, - Off, -} - -#[derive(Clone, Debug, PartialEq)] -pub struct Settings { - pub version: String, - pub default_host_triple: Option, - pub default_toolchain: Option, - pub overrides: BTreeMap, - pub telemetry: TelemetryMode -} - -impl Default for Settings { - fn default() -> Self { - Settings { - version: DEFAULT_METADATA_VERSION.to_owned(), - default_host_triple: None, - default_toolchain: None, - overrides: BTreeMap::new(), - telemetry: TelemetryMode::Off - } - } -} - -impl Settings { - fn path_to_key(path: &Path, notify_handler: &Fn(Notification)) -> String { - utils::canonicalize_path(path, &|n| notify_handler(n.into())) - .display() - .to_string() - } - - pub fn remove_override(&mut self, path: &Path, notify_handler: &Fn(Notification)) -> bool { - let key = Self::path_to_key(path, notify_handler); - self.overrides.remove(&key).is_some() - } - - pub fn add_override(&mut self, path: &Path, toolchain: String, notify_handler: &Fn(Notification)) { - let key = Self::path_to_key(path, notify_handler); - notify_handler(Notification::SetOverrideToolchain(path, &toolchain)); - self.overrides.insert(key, toolchain); - } - - pub fn find_override(&self, dir_unresolved: &Path, notify_handler: &Fn(Notification)) - -> Option<(String, PathBuf)> { - let dir = utils::canonicalize_path(dir_unresolved, &|n| notify_handler(n.into())); - let mut maybe_path = Some(&*dir); - while let Some(path) = maybe_path { - let key = Self::path_to_key(path, notify_handler); - if let Some(toolchain) = self.overrides.get(&key) { - return Some((toolchain.to_owned(), path.to_owned())); - } - maybe_path = path.parent(); - } - None - } - - pub fn parse(data: &str) -> Result { - let mut parser = toml::Parser::new(data); - let value = try!(parser.parse().ok_or_else(move || ErrorKind::ParsingSettings(parser.errors))); - - Self::from_toml(value, "") - } - pub fn stringify(self) -> String { - toml::Value::Table(self.to_toml()).to_string() - } - - pub fn from_toml(mut table: toml::Table, path: &str) -> Result { - let version = try!(get_string(&mut table, "version", path)); - if !SUPPORTED_METADATA_VERSIONS.contains(&&*version) { - return Err(ErrorKind::UnknownMetadataVersion(version).into()); - } - Ok(Settings { - version: version, - default_host_triple: try!(get_opt_string(&mut table, "default_host_triple", path)), - default_toolchain: try!(get_opt_string(&mut table, "default_toolchain", path)), - overrides: try!(Self::table_to_overrides(&mut table, path)), - telemetry: if try!(get_opt_bool(&mut table, "telemetry", path)).unwrap_or(false) { - TelemetryMode::On - } else { - TelemetryMode::Off - } - }) - } - pub fn to_toml(self) -> toml::Table { - let mut result = toml::Table::new(); - - result.insert("version".to_owned(), - toml::Value::String(self.version)); - - if let Some(v) = self.default_host_triple { - result.insert("default_host_triple".to_owned(), toml::Value::String(v)); - } - - if let Some(v) = self.default_toolchain { - result.insert("default_toolchain".to_owned(), toml::Value::String(v)); - } - - let overrides = Self::overrides_to_table(self.overrides); - result.insert("overrides".to_owned(), toml::Value::Table(overrides)); - - let telemetry = self.telemetry == TelemetryMode::On; - result.insert("telemetry".to_owned(), toml::Value::Boolean(telemetry)); - - result - } - - fn table_to_overrides(table: &mut toml::Table, path: &str) -> Result> { - let mut result = BTreeMap::new(); - let pkg_table = try!(get_table(table, "overrides", path)); - - for (k, v) in pkg_table { - if let toml::Value::String(t) = v { - result.insert(k, t); - } - } - - Ok(result) - } - - fn overrides_to_table(overrides: BTreeMap) -> toml::Table { - let mut result = toml::Table::new(); - for (k, v) in overrides { - result.insert(k, toml::Value::String(v)); - } - result - } -} +use errors::*; +use notifications::*; +use toml_utils::*; +use utils; +use toml; +use std::collections::BTreeMap; +use std::path::{Path, PathBuf}; +use std::cell::RefCell; +use std::str::FromStr; + +pub const SUPPORTED_METADATA_VERSIONS: [&'static str; 2] = ["2", "12"]; +pub const DEFAULT_METADATA_VERSION: &'static str = "12"; + + +#[derive(Clone, Debug, PartialEq)] +pub struct SettingsFile { + path: PathBuf, + cache: RefCell> +} + +impl SettingsFile { + pub fn new(path: PathBuf) -> Self { + SettingsFile { + path: path, + cache: RefCell::new(None) + } + } + fn write_settings(&self) -> Result<()> { + let s = self.cache.borrow().as_ref().unwrap().clone(); + try!(utils::write_file("settings", &self.path, &s.stringify())); + Ok(()) + } + fn read_settings(&self) -> Result<()> { + let mut needs_save = false; + { + let mut b = self.cache.borrow_mut(); + if b.is_none() { + *b = Some(if utils::is_file(&self.path) { + let content = try!(utils::read_file("settings", &self.path)); + try!(Settings::parse(&content)) + } else { + needs_save = true; + Default::default() + }); + } + } + if needs_save { + try!(self.write_settings()); + } + Ok(()) + } + pub fn with Result>(&self, f: F) -> Result { + try!(self.read_settings()); + + // Settings can no longer be None so it's OK to unwrap + f(self.cache.borrow().as_ref().unwrap()) + } + pub fn with_mut Result>(&self, f: F) -> Result { + try!(self.read_settings()); + + // Settings can no longer be None so it's OK to unwrap + let result = { + try!(f(self.cache.borrow_mut().as_mut().unwrap())) + }; + try!(self.write_settings()); + Ok(result) + } + pub fn maybe_upgrade_from_legacy(&self, multirust_dir: &Path) -> Result<()> { + // Data locations + let legacy_version_file = multirust_dir.join("version"); + if utils::is_file(&legacy_version_file) { + fn split_override(s: &str, separator: char) -> Option<(T, T)> { + s.find(separator).and_then(|index| { + match (T::from_str(&s[..index]), T::from_str(&s[index + 1..])) { + (Ok(l), Ok(r)) => Some((l, r)), + _ => None + } + }) + } + + let override_db = multirust_dir.join("overrides"); + let default_file = multirust_dir.join("default"); + let telemetry_file = multirust_dir.join("telemetry-on"); + // Legacy upgrade + try!(self.with_mut(|s| { + s.version = try!(utils::read_file("version", &legacy_version_file)) + .trim().to_owned(); + + if utils::is_file(&default_file) { + s.default_toolchain = Some(try!(utils::read_file("default", &default_file)) + .trim().to_owned()); + } + if utils::is_file(&override_db) { + let overrides = try!(utils::read_file("overrides", &override_db)); + for o in overrides.lines() { + if let Some((k, v)) = split_override(o, ';') { + s.overrides.insert(k, v); + } + } + } + if utils::is_file(&telemetry_file) { + s.telemetry = TelemetryMode::On; + } + Ok(()) + })); + + // Failure to delete these is not a fatal error + let _ = utils::remove_file("version", &legacy_version_file); + let _ = utils::remove_file("default", &default_file); + let _ = utils::remove_file("overrides", &override_db); + let _ = utils::remove_file("telemetry", &telemetry_file); + } + Ok(()) + } +} + + +#[derive(Copy, Clone, Debug, PartialEq)] +pub enum TelemetryMode { + On, + Off, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct Settings { + pub version: String, + pub default_host_triple: Option, + pub default_toolchain: Option, + pub overrides: BTreeMap, + pub telemetry: TelemetryMode +} + +impl Default for Settings { + fn default() -> Self { + Settings { + version: DEFAULT_METADATA_VERSION.to_owned(), + default_host_triple: None, + default_toolchain: None, + overrides: BTreeMap::new(), + telemetry: TelemetryMode::Off + } + } +} + +impl Settings { + fn path_to_key(path: &Path, notify_handler: &Fn(Notification)) -> String { + utils::canonicalize_path(path, &|n| notify_handler(n.into())) + .display() + .to_string() + } + + pub fn remove_override(&mut self, path: &Path, notify_handler: &Fn(Notification)) -> bool { + let key = Self::path_to_key(path, notify_handler); + self.overrides.remove(&key).is_some() + } + + pub fn add_override(&mut self, path: &Path, toolchain: String, notify_handler: &Fn(Notification)) { + let key = Self::path_to_key(path, notify_handler); + notify_handler(Notification::SetOverrideToolchain(path, &toolchain)); + self.overrides.insert(key, toolchain); + } + + pub fn find_override(&self, dir_unresolved: &Path, notify_handler: &Fn(Notification)) + -> Option<(String, PathBuf)> { + let dir = utils::canonicalize_path(dir_unresolved, &|n| notify_handler(n.into())); + let mut maybe_path = Some(&*dir); + while let Some(path) = maybe_path { + let key = Self::path_to_key(path, notify_handler); + if let Some(toolchain) = self.overrides.get(&key) { + return Some((toolchain.to_owned(), path.to_owned())); + } + maybe_path = path.parent(); + } + None + } + + pub fn parse(data: &str) -> Result { + let mut parser = toml::Parser::new(data); + let value = try!(parser.parse().ok_or_else(move || ErrorKind::ParsingSettings(parser.errors))); + + Self::from_toml(value, "") + } + pub fn stringify(self) -> String { + toml::Value::Table(self.to_toml()).to_string() + } + + pub fn from_toml(mut table: toml::Table, path: &str) -> Result { + let version = try!(get_string(&mut table, "version", path)); + if !SUPPORTED_METADATA_VERSIONS.contains(&&*version) { + return Err(ErrorKind::UnknownMetadataVersion(version).into()); + } + Ok(Settings { + version: version, + default_host_triple: try!(get_opt_string(&mut table, "default_host_triple", path)), + default_toolchain: try!(get_opt_string(&mut table, "default_toolchain", path)), + overrides: try!(Self::table_to_overrides(&mut table, path)), + telemetry: if try!(get_opt_bool(&mut table, "telemetry", path)).unwrap_or(false) { + TelemetryMode::On + } else { + TelemetryMode::Off + } + }) + } + pub fn to_toml(self) -> toml::Table { + let mut result = toml::Table::new(); + + result.insert("version".to_owned(), + toml::Value::String(self.version)); + + if let Some(v) = self.default_host_triple { + result.insert("default_host_triple".to_owned(), toml::Value::String(v)); + } + + if let Some(v) = self.default_toolchain { + result.insert("default_toolchain".to_owned(), toml::Value::String(v)); + } + + let overrides = Self::overrides_to_table(self.overrides); + result.insert("overrides".to_owned(), toml::Value::Table(overrides)); + + let telemetry = self.telemetry == TelemetryMode::On; + result.insert("telemetry".to_owned(), toml::Value::Boolean(telemetry)); + + result + } + + fn table_to_overrides(table: &mut toml::Table, path: &str) -> Result> { + let mut result = BTreeMap::new(); + let pkg_table = try!(get_table(table, "overrides", path)); + + for (k, v) in pkg_table { + if let toml::Value::String(t) = v { + result.insert(k, t); + } + } + + Ok(result) + } + + fn overrides_to_table(overrides: BTreeMap) -> toml::Table { + let mut result = toml::Table::new(); + for (k, v) in overrides { + result.insert(k, toml::Value::String(v)); + } + result + } +} diff --git a/www/fonts/OFL.txt b/www/fonts/OFL.txt index 91ed5986a3..d9ae615922 100644 --- a/www/fonts/OFL.txt +++ b/www/fonts/OFL.txt @@ -1,92 +1,92 @@ -Copyright (c) 2011, Raph Levien (firstname.lastname@gmail.com), Copyright (c) 2012, Cyreal (cyreal.org) -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. +Copyright (c) 2011, Raph Levien (firstname.lastname@gmail.com), Copyright (c) 2012, Cyreal (cyreal.org) +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE.