Skip to content

Commit

Permalink
- Adds component subcommand
Browse files Browse the repository at this point in the history
- Fixes inconsistent 8-column tab indentation
- Convert British spellings to US
  • Loading branch information
Diggsey committed Aug 17, 2016
1 parent 95f38e8 commit e0e4dd3
Show file tree
Hide file tree
Showing 22 changed files with 667 additions and 486 deletions.
2 changes: 1 addition & 1 deletion LICENSE-APACHE
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
18 changes: 9 additions & 9 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ main() {

local _ext=""
case "$_arch" in
*windows*)
_ext=".exe"
;;
*windows*)
_ext=".exe"
;;
esac

local _url="$RUSTUP_UPDATE_ROOT/$_arch/rustup-init$_ext"
Expand All @@ -48,9 +48,9 @@ main() {
ensure curl -sSfL "$_url" -o "$_file"
ensure chmod u+x "$_file"
if [ ! -x "$_file" ]; then
echo "Cannot execute $_file (likely because of mounting /tmp as noexec)."
echo "Please copy the file to a location where you can execute binaries and run ./rustup-init$_ext."
exit 1
echo "Cannot execute $_file (likely because of mounting /tmp as noexec)."
echo "Please copy the file to a location where you can execute binaries and run ./rustup-init$_ext."
exit 1
fi

# check if we have to use /dev/tty to prompt the user
Expand Down Expand Up @@ -149,9 +149,9 @@ get_architecture() {
local _ostype="${_ostype}eabihf"
;;

aarch64)
local _cputype=aarch64
;;
aarch64)
local _cputype=aarch64
;;

x86_64 | x86-64 | x64 | amd64)
local _cputype=x86_64
Expand Down
34 changes: 17 additions & 17 deletions src/ca-loader/src/sys/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ impl IntoIterator for CertBundle {
type IntoIter = CertIter;

fn into_iter(self) -> Self::IntoIter {
CertIter { it: Box::new(self.rv.into_iter()) }
CertIter { it: Box::new(self.rv.into_iter()) }
}
}

impl Iterator for CertIter {
type Item = CertItem;

fn next(&mut self) -> Option<CertItem> {
if let Some(res) = self.it.next() {
if let Some(ref rref) = res.reference {
match rref {
&Reference::Certificate(ref cert) => return Some(CertItem::Blob(cert.to_der())),
_ => ()
}
}
return self.next();
}
None
if let Some(res) = self.it.next() {
if let Some(ref rref) = res.reference {
match rref {
&Reference::Certificate(ref cert) => return Some(CertItem::Blob(cert.to_der())),
_ => ()
}
}
return self.next();
}
None
}
}

impl CertBundle {
pub fn new() -> Result<CertBundle, ()> {
let root_kc = try!(SecKeychain::open("/System/Library/Keychains/SystemRootCertificates.keychain").map_err(|_| ()));
let chains = [ root_kc ];
let mut opts = ItemSearchOptions::new();
let opts = opts.keychains(&chains).class(ItemClass::Certificate).load_refs(true).limit(i32::MAX as i64);
let rv = try!(opts.search().map_err(|_| ()));
Ok(CertBundle { rv: rv })
let root_kc = try!(SecKeychain::open("/System/Library/Keychains/SystemRootCertificates.keychain").map_err(|_| ()));
let chains = [ root_kc ];
let mut opts = ItemSearchOptions::new();
let opts = opts.keychains(&chains).class(ItemClass::Certificate).load_refs(true).limit(i32::MAX as i64);
let rv = try!(opts.search().map_err(|_| ()));
Ok(CertBundle { rv: rv })
}
}
14 changes: 7 additions & 7 deletions src/ca-loader/src/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
cfg_if! {
if #[cfg(windows)] {
mod windows;
pub use self::windows::CertBundle;
mod windows;
pub use self::windows::CertBundle;
} else if #[cfg(target_os = "macos")] {
mod macos;
pub use self::macos::CertBundle;
mod macos;
pub use self::macos::CertBundle;
} else if #[cfg(unix)] {
mod unix;
pub use self::unix::CertBundle;
mod unix;
pub use self::unix::CertBundle;
} else {
// Unknown
// Unknown
}
}
212 changes: 106 additions & 106 deletions src/ca-loader/src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,78 +8,78 @@ use super::super::CertItem;

cfg_if! {
if #[cfg(any(target_os = "android", target_os = "solaris"))] {
use std::fs::{read_dir, ReadDir};

pub struct CertBundle(&'static str);

pub struct CertIter(&'static str, Option<ReadDir>);

impl IntoIterator for CertBundle {
type Item = CertItem;
type IntoIter = CertIter;

fn into_iter(self) -> Self::IntoIter {
if let Ok(dir) = read_dir(self.0) {
CertIter(self.0, Some(dir))
} else {
CertIter(self.0, None)
}
}
}

impl Iterator for CertIter {
type Item = CertItem;

fn next(&mut self) -> Option<Self::Item> {
match self.1 {
None => return None,
Some(ref mut dir) => {
match dir.next() {
None => return None,
Some(Err(_)) => return None,
Some(Ok(ref de)) => {
if let Ok(ftyp) = de.file_type() {
if !ftyp.is_dir() {
if let Some(s) = de.file_name().to_str() {
let mut full_name = String::from(self.0);
full_name.push('/');
full_name.push_str(s);
return Some(CertItem::File(full_name));
}
}
}
}
}
}
}
self.next()
}
}

impl CertBundle {
pub fn new() -> Result<CertBundle, ()> {
Ok(CertBundle(try!(sys_path())))
}
}
use std::fs::{read_dir, ReadDir};

pub struct CertBundle(&'static str);

pub struct CertIter(&'static str, Option<ReadDir>);

impl IntoIterator for CertBundle {
type Item = CertItem;
type IntoIter = CertIter;

fn into_iter(self) -> Self::IntoIter {
if let Ok(dir) = read_dir(self.0) {
CertIter(self.0, Some(dir))
} else {
CertIter(self.0, None)
}
}
}

impl Iterator for CertIter {
type Item = CertItem;

fn next(&mut self) -> Option<Self::Item> {
match self.1 {
None => return None,
Some(ref mut dir) => {
match dir.next() {
None => return None,
Some(Err(_)) => return None,
Some(Ok(ref de)) => {
if let Ok(ftyp) = de.file_type() {
if !ftyp.is_dir() {
if let Some(s) = de.file_name().to_str() {
let mut full_name = String::from(self.0);
full_name.push('/');
full_name.push_str(s);
return Some(CertItem::File(full_name));
}
}
}
}
}
}
}
self.next()
}
}

impl CertBundle {
pub fn new() -> Result<CertBundle, ()> {
Ok(CertBundle(try!(sys_path())))
}
}
} else {
use std::option;
use std::option;

pub struct CertBundle(Option<CertItem>);
pub struct CertBundle(Option<CertItem>);

impl IntoIterator for CertBundle {
type Item = CertItem;
type IntoIter = option::IntoIter<CertItem>;
impl IntoIterator for CertBundle {
type Item = CertItem;
type IntoIter = option::IntoIter<CertItem>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

impl CertBundle {
pub fn new() -> Result<CertBundle, ()> {
Ok(CertBundle(Some(CertItem::File(try!(sys_path()).to_string()))))
}
}
impl CertBundle {
pub fn new() -> Result<CertBundle, ()> {
Ok(CertBundle(Some(CertItem::File(try!(sys_path()).to_string()))))
}
}
}
}

Expand All @@ -91,50 +91,50 @@ pub fn sys_path() -> Result<&'static str, ()> {
// the contents of struct utsname on input, and will fill it with
// properly NUL-terminated strings on successful return.
unsafe {
let mut uts = mem::uninitialized::<libc::utsname>();

if libc::uname(&mut uts) < 0 {
return Err(());
}
let sysname = try!(CStr::from_ptr(uts.sysname.as_ptr()).to_str().map_err(|_| ()));
let release = try!(CStr::from_ptr(uts.release.as_ptr()).to_str().map_err(|_| ()));
let path = match sysname {
"FreeBSD" | "OpenBSD" => "/etc/ssl/cert.pem",
"NetBSD" => "/etc/ssl/certs",
"Linux" => linux_distro_guess_ca_path(),
"SunOS" => {
let major = release.split('.').take(1).collect::<String>();
let major = major.parse::<u32>().unwrap_or(5);
let minor = release.split('.').skip(1).take(1).collect::<String>();
let minor = minor.parse::<u32>().unwrap_or(10);
if major < 5 || (major == 5 && minor < 11) {
"/opt/csw/share/cacertificates/mozilla"
} else {
"/etc/certs/CA"
}
}
_ => unimplemented!()
};
Ok(path)
let mut uts = mem::uninitialized::<libc::utsname>();

if libc::uname(&mut uts) < 0 {
return Err(());
}
let sysname = try!(CStr::from_ptr(uts.sysname.as_ptr()).to_str().map_err(|_| ()));
let release = try!(CStr::from_ptr(uts.release.as_ptr()).to_str().map_err(|_| ()));
let path = match sysname {
"FreeBSD" | "OpenBSD" => "/etc/ssl/cert.pem",
"NetBSD" => "/etc/ssl/certs",
"Linux" => linux_distro_guess_ca_path(),
"SunOS" => {
let major = release.split('.').take(1).collect::<String>();
let major = major.parse::<u32>().unwrap_or(5);
let minor = release.split('.').skip(1).take(1).collect::<String>();
let minor = minor.parse::<u32>().unwrap_or(10);
if major < 5 || (major == 5 && minor < 11) {
"/opt/csw/share/cacertificates/mozilla"
} else {
"/etc/certs/CA"
}
}
_ => unimplemented!()
};
Ok(path)
}
}

cfg_if! {
if #[cfg(target_os = "android")] {
fn linux_distro_guess_ca_path() -> &'static str {
"/system/etc/security/cacerts"
}
fn linux_distro_guess_ca_path() -> &'static str {
"/system/etc/security/cacerts"
}
} else {
fn linux_distro_guess_ca_path() -> &'static str {
if let Ok(_debian) = fs::metadata("/etc/debian_version") {
"/etc/ssl/certs/ca-certificates.crt"
} else if let Ok(_rh) = fs::metadata("/etc/redhat-release") {
"/etc/pki/tls/certs/ca-bundle.crt"
} else if let Ok(_suse) = fs::metadata("/etc/SuSE-release") {
"/etc/ssl/ca-bundle.pem"
} else { // fallback
"/etc/pki/tls/cacert.pem"
}
}
fn linux_distro_guess_ca_path() -> &'static str {
if let Ok(_debian) = fs::metadata("/etc/debian_version") {
"/etc/ssl/certs/ca-certificates.crt"
} else if let Ok(_rh) = fs::metadata("/etc/redhat-release") {
"/etc/pki/tls/certs/ca-bundle.crt"
} else if let Ok(_suse) = fs::metadata("/etc/SuSE-release") {
"/etc/ssl/ca-bundle.pem"
} else { // fallback
"/etc/pki/tls/cacert.pem"
}
}
}
}
Loading

0 comments on commit e0e4dd3

Please sign in to comment.