Skip to content

Commit 4428fb1

Browse files
committed
---
yaml --- r: 161774 b: refs/heads/master c: 5263600 h: refs/heads/master v: v3
1 parent 2edbb99 commit 4428fb1

File tree

11 files changed

+201
-100
lines changed

11 files changed

+201
-100
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 602fc781ff0990b7f94851e210c6a4a516c80935
2+
refs/heads/master: 52636007ce40da67998276c0671c6345512c3b58
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cafe2966770ff377aad6dd9fd808e68055587c58
55
refs/heads/try: 0f0d21c1eb5c7be04d323e0b06faf252ad790af6

trunk/src/etc/rustup.sh

100644100755
Lines changed: 86 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ flag() {
188188
fi
189189
}
190190

191-
validate_opt () {
191+
validate_opt() {
192192
for arg in $CFG_ARGS
193193
do
194194
isArgValid=0
@@ -230,6 +230,7 @@ validate_opt () {
230230
}
231231

232232
probe_need CFG_CURL curl
233+
probe_need CFG_TAR tar
233234

234235
CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
235236
CFG_SELF="$0"
@@ -388,89 +389,109 @@ esac
388389

389390
msg "host triple: ${HOST_TRIPLE}"
390391

391-
PACKAGE_NAME=rust-nightly
392-
PACKAGE_NAME_AND_TRIPLE="${PACKAGE_NAME}-${HOST_TRIPLE}"
393-
TARBALL_NAME="${PACKAGE_NAME_AND_TRIPLE}.tar.gz"
394-
REMOTE_TARBALL="https://static.rust-lang.org/dist/${TARBALL_NAME}"
395-
TMP_DIR="./rustup-tmp-install"
396-
LOCAL_TARBALL="${TMP_DIR}/${TARBALL_NAME}"
397-
LOCAL_INSTALL_DIR="${TMP_DIR}/${PACKAGE_NAME_AND_TRIPLE}"
398-
LOCAL_INSTALL_SCRIPT="${LOCAL_INSTALL_DIR}/install.sh"
392+
CFG_INSTALL_FLAGS=""
393+
if [ -n "${CFG_UNINSTALL}" ]
394+
then
395+
CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --uninstall"
396+
fi
397+
398+
if [ -n "${CFG_PREFIX}" ]
399+
then
400+
CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --prefix=${CFG_PREFIX}"
401+
fi
402+
403+
CFG_TMP_DIR="./rustup-tmp-install"
399404

405+
RUST_URL="https://static.rust-lang.org/dist"
406+
RUST_PACKAGE_NAME=rust-nightly
407+
RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}"
408+
RUST_TARBALL_NAME="${RUST_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
409+
RUST_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${RUST_PACKAGE_NAME_AND_TRIPLE}"
410+
RUST_LOCAL_INSTALL_SCRIPT="${RUST_LOCAL_INSTALL_DIR}/install.sh"
411+
412+
CARGO_URL="https://static.rust-lang.org/cargo-dist"
400413
CARGO_PACKAGE_NAME=cargo-nightly
401414
CARGO_PACKAGE_NAME_AND_TRIPLE="${CARGO_PACKAGE_NAME}-${HOST_TRIPLE}"
402415
CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
403-
CARGO_REMOTE_TARBALL="https://static.rust-lang.org/cargo-dist/${CARGO_TARBALL_NAME}"
404-
CARGO_LOCAL_TARBALL="${TMP_DIR}/${CARGO_TARBALL_NAME}"
405-
CARGO_LOCAL_INSTALL_DIR="${TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}"
416+
CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}"
406417
CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh"
407418

408-
rm -Rf "${TMP_DIR}"
409-
need_ok "failed to remove temporary installation directory"
419+
# Fetch the package.
420+
download_package() {
421+
remote_tarball="$1"
422+
local_tarball="$2"
410423

411-
mkdir -p "${TMP_DIR}"
412-
need_ok "failed to create create temporary installation directory"
424+
msg "Downloading ${remote_tarball} to ${local_tarball}"
413425

414-
msg "downloading rust installer"
415-
"${CFG_CURL}" "${REMOTE_TARBALL}" > "${LOCAL_TARBALL}"
416-
if [ $? -ne 0 ]
417-
then
418-
rm -Rf "${TMP_DIR}"
419-
err "failed to download installer"
420-
fi
426+
mkdir -p "${CFG_TMP_DIR}"
427+
need_ok "failed to create create download directory"
421428

422-
if [ -z "${CFG_DISABLE_CARGO}" ]; then
423-
msg "downloading cargo installer"
424-
"${CFG_CURL}" "${CARGO_REMOTE_TARBALL}" > "${CARGO_LOCAL_TARBALL}"
429+
"${CFG_CURL}" -f -o "${local_tarball}" "${remote_tarball}"
425430
if [ $? -ne 0 ]
426431
then
427-
rm -Rf "${TMP_DIR}"
428-
err "failed to download cargo installer"
432+
rm -Rf "${CFG_TMP_DIR}"
433+
err "failed to download installer"
429434
fi
430-
fi
435+
}
431436

437+
# Wrap all the commands needed to install a package.
438+
install_package() {
439+
tarball_name="$1"
440+
install_script="$2"
432441

433-
(cd "${TMP_DIR}" && tar xzf "${TARBALL_NAME}")
434-
if [ $? -ne 0 ]
435-
then
436-
rm -Rf "${TMP_DIR}"
442+
msg "Extracting ${tarball_name}"
443+
(cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xvf "${tarball_name}")
444+
if [ $? -ne 0 ]; then
445+
rm -Rf "${CFG_TMP_DIR}"
437446
err "failed to unpack installer"
438-
fi
439-
440-
MAYBE_UNINSTALL=
441-
if [ -n "${CFG_UNINSTALL}" ]
442-
then
443-
MAYBE_UNINSTALL="--uninstall"
444-
fi
445-
446-
MAYBE_PREFIX=
447-
if [ -n "${CFG_PREFIX}" ]
448-
then
449-
MAYBE_PREFIX="--prefix=${CFG_PREFIX}"
450-
fi
451-
452-
sh "${LOCAL_INSTALL_SCRIPT}" "${MAYBE_UNINSTALL}" "${MAYBE_PREFIX}"
453-
if [ $? -ne 0 ]
454-
then
455-
rm -Rf "${TMP_DIR}"
456-
err "failed to install Rust"
457-
fi
447+
fi
458448

459-
if [ -z "${CFG_DISABLE_CARGO}" ]; then
460-
(cd "${TMP_DIR}" && tar xzf "${CARGO_TARBALL_NAME}")
449+
sh "${install_script}" "${CFG_INSTALL_FLAGS}"
461450
if [ $? -ne 0 ]
462451
then
463-
rm -Rf "${TMP_DIR}"
464-
err "failed to unpack cargo installer"
452+
rm -Rf "${CFG_TMP_DIR}"
453+
err "failed to install Rust"
465454
fi
455+
}
466456

467-
sh "${CARGO_LOCAL_INSTALL_SCRIPT}" "${MAYBE_UNINSTALL}" "${MAYBE_PREFIX}"
468-
if [ $? -ne 0 ]
469-
then
470-
rm -Rf "${TMP_DIR}"
471-
err "failed to install Cargo"
457+
# It's possible that curl could be interrupted partway though downloading
458+
# `rustup.sh`, truncating the file. This could be especially bad if we were in
459+
# the middle of a line that would run "rm -rf ". To protect against this, we
460+
# wrap up the `rustup.sh` destructive functionality in this helper function,
461+
# which we call as the last thing we do. This means we will not do anything
462+
# unless we have the entire file downloaded.
463+
install_packages() {
464+
rm -Rf "${CFG_TMP_DIR}"
465+
need_ok "failed to remove temporary installation directory"
466+
467+
mkdir -p "${CFG_TMP_DIR}"
468+
need_ok "failed to create create temporary installation directory"
469+
470+
RUST_LOCAL_TARBALL="${CFG_TMP_DIR}/${RUST_TARBALL_NAME}"
471+
CARGO_LOCAL_TARBALL="${CFG_TMP_DIR}/${CARGO_TARBALL_NAME}"
472+
473+
download_package \
474+
"${RUST_URL}/${RUST_TARBALL_NAME}" \
475+
"${RUST_LOCAL_TARBALL}"
476+
477+
if [ -z "${CFG_DISABLE_CARGO}" ]; then
478+
download_package \
479+
"${CARGO_URL}/${CARGO_TARBALL_NAME}" \
480+
"${CARGO_LOCAL_TARBALL}"
472481
fi
473-
fi
474482

475-
rm -Rf "${TMP_DIR}"
476-
need_ok "couldn't rm temporary installation directory"
483+
install_package \
484+
"${RUST_TARBALL_NAME}" \
485+
"${RUST_LOCAL_INSTALL_SCRIPT}"
486+
487+
if [ -z "${CFG_DISABLE_CARGO}" ]; then
488+
install_package \
489+
"${CARGO_TARBALL_NAME}" \
490+
"${CARGO_LOCAL_INSTALL_SCRIPT}"
491+
fi
492+
493+
rm -Rf "${CFG_TMP_DIR}"
494+
need_ok "couldn't rm temporary installation directory"
495+
}
496+
497+
install_packages

trunk/src/libcore/result.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,14 @@ impl<T, E> Result<T, E> {
444444
/// ignoring I/O and parse errors:
445445
///
446446
/// ```
447-
/// use std::io::{BufReader, IoResult};
447+
/// use std::io::IoResult;
448448
///
449-
/// let buffer = "1\n2\n3\n4\n";
450-
/// let mut reader = BufReader::new(buffer.as_bytes());
449+
/// let mut buffer = &mut b"1\n2\n3\n4\n";
451450
///
452451
/// let mut sum = 0;
453452
///
454-
/// while !reader.eof() {
455-
/// let line: IoResult<String> = reader.read_line();
453+
/// while !buffer.is_empty() {
454+
/// let line: IoResult<String> = buffer.read_line();
456455
/// // Convert the string line to a number using `map` and `from_str`
457456
/// let val: IoResult<int> = line.map(|line| {
458457
/// from_str::<int>(line.as_slice().trim_right()).unwrap_or(0)

trunk/src/libgraphviz/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ mod tests {
547547
use self::NodeLabels::*;
548548
use super::{Id, LabelText, LabelStr, EscStr, Labeller};
549549
use super::{Nodes, Edges, GraphWalk, render};
550-
use std::io::{BufReader, IoResult};
550+
use std::io::IoResult;
551551
use std::str;
552552

553553
/// each node is an index in a vector in the graph.
@@ -698,8 +698,7 @@ mod tests {
698698
fn test_input(g: LabelledGraph) -> IoResult<String> {
699699
let mut writer = Vec::new();
700700
render(&g, &mut writer).unwrap();
701-
let mut r = BufReader::new(writer[]);
702-
r.read_to_string()
701+
(&mut writer.as_slice()).read_to_string()
703702
}
704703

705704
// All of the tests use raw-strings as the format for the expected outputs,
@@ -811,8 +810,7 @@ r#"digraph hasse_diagram {
811810
edge(1, 3, ";"), edge(2, 3, ";" )));
812811

813812
render(&g, &mut writer).unwrap();
814-
let mut r = BufReader::new(writer[]);
815-
let r = r.read_to_string();
813+
let r = (&mut writer.as_slice()).read_to_string();
816814

817815
assert_eq!(r.unwrap().as_slice(),
818816
r#"digraph syntax_tree {

trunk/src/libstd/io/buffered.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ mod test {
406406
use prelude::*;
407407
use super::*;
408408
use super::super::{IoResult, EndOfFile};
409-
use super::super::mem::{MemReader, BufReader};
409+
use super::super::mem::MemReader;
410410
use self::test::Bencher;
411411
use str::StrPrelude;
412412

@@ -626,14 +626,14 @@ mod test {
626626
#[test]
627627
fn read_char_buffered() {
628628
let buf = [195u8, 159u8];
629-
let mut reader = BufferedReader::with_capacity(1, BufReader::new(&buf));
629+
let mut reader = BufferedReader::with_capacity(1, buf[]);
630630
assert_eq!(reader.read_char(), Ok('ß'));
631631
}
632632

633633
#[test]
634634
fn test_chars() {
635635
let buf = [195u8, 159u8, b'a'];
636-
let mut reader = BufferedReader::with_capacity(1, BufReader::new(&buf));
636+
let mut reader = BufferedReader::with_capacity(1, buf[]);
637637
let mut it = reader.chars();
638638
assert_eq!(it.next(), Some(Ok('ß')));
639639
assert_eq!(it.next(), Some(Ok('a')));

trunk/src/libstd/io/fs.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
use clone::Clone;
5454
use io::standard_error;
5555
use io::{FilePermission, Write, Open, FileAccess, FileMode, FileType};
56-
use io::{IoResult, IoError, FileStat, SeekStyle, Seek, Writer, Reader};
56+
use io::{IoResult, IoError, InvalidInput};
57+
use io::{FileStat, SeekStyle, Seek, Writer, Reader};
5758
use io::{Read, Truncate, ReadWrite, Append};
5859
use io::UpdateIoError;
5960
use io;
@@ -134,13 +135,26 @@ impl File {
134135
pub fn open_mode(path: &Path,
135136
mode: FileMode,
136137
access: FileAccess) -> IoResult<File> {
137-
fs_imp::open(path, mode, access).map(|fd| {
138-
File {
139-
path: path.clone(),
140-
fd: fd,
141-
last_nread: -1
138+
fs_imp::open(path, mode, access).and_then(|fd| {
139+
// On *BSD systems, we can open a directory as a file and read from it:
140+
// fd=open("/tmp", O_RDONLY); read(fd, buf, N);
141+
// due to an old tradition before the introduction of opendir(3).
142+
// We explicitly reject it because there are few use cases.
143+
if cfg!(not(any(windows, target_os = "linux", target_os = "android"))) &&
144+
try!(fd.fstat()).kind == FileType::Directory {
145+
Err(IoError {
146+
kind: InvalidInput,
147+
desc: "is a directory",
148+
detail: None
149+
})
150+
} else {
151+
Ok(File {
152+
path: path.clone(),
153+
fd: fd,
154+
last_nread: -1
155+
})
142156
}
143-
}).update_err("couldn't open file", |e| {
157+
}).update_err("couldn't open path as file", |e| {
144158
format!("{}; path={}; mode={}; access={}", e, path.display(),
145159
mode_string(mode), access_string(access))
146160
})
@@ -237,7 +251,7 @@ impl File {
237251
}
238252

239253
/// Queries information about the underlying file.
240-
pub fn stat(&mut self) -> IoResult<FileStat> {
254+
pub fn stat(&self) -> IoResult<FileStat> {
241255
self.fd.fstat()
242256
.update_err("couldn't fstat file", |e|
243257
format!("{}; path={}", e, self.path.display()))
@@ -886,7 +900,7 @@ mod test {
886900
let filename = &tmpdir.join("file_that_does_not_exist.txt");
887901
let result = File::open_mode(filename, Open, Read);
888902

889-
error!(result, "couldn't open file");
903+
error!(result, "couldn't open path as file");
890904
if cfg!(unix) {
891905
error!(result, "no such file or directory");
892906
}

0 commit comments

Comments
 (0)