Skip to content

Commit ee24bb1

Browse files
authored
Merge branch 'master' into rustup-from-non-existing-path
2 parents 5f8b236 + 027ac51 commit ee24bb1

File tree

10 files changed

+169
-195
lines changed

10 files changed

+169
-195
lines changed

build.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,19 @@ fn commit_info() -> String {
3636
}
3737

3838
fn commit_hash() -> Result<String, Ignore> {
39-
Ok(try!(String::from_utf8(
40-
try!(
41-
Command::new("git")
42-
.args(&["rev-parse", "--short=9", "HEAD"])
43-
.output()
44-
).stdout
45-
)))
39+
Ok(String::from_utf8(
40+
Command::new("git")
41+
.args(&["rev-parse", "--short=9", "HEAD"])
42+
.output()?
43+
.stdout,
44+
)?)
4645
}
4746

4847
fn commit_date() -> Result<String, Ignore> {
49-
Ok(try!(String::from_utf8(
50-
try!(
51-
Command::new("git")
52-
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
53-
.output()
54-
).stdout
55-
)))
48+
Ok(String::from_utf8(
49+
Command::new("git")
50+
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
51+
.output()?
52+
.stdout,
53+
)?)
5654
}

src/download/src/lib.rs

+70-98
Original file line numberDiff line numberDiff line change
@@ -60,73 +60,65 @@ pub fn download_to_path_with_backend(
6060

6161
let downloaded_so_far = if let Ok(mut partial) = possible_partial {
6262
if let Some(cb) = callback {
63-
try!(cb(Event::ResumingPartialDownload));
63+
cb(Event::ResumingPartialDownload)?;
6464

6565
let mut buf = vec![0; 32768];
6666
let mut downloaded_so_far = 0;
6767
loop {
68-
let n = try!(partial.read(&mut buf));
68+
let n = partial.read(&mut buf)?;
6969
downloaded_so_far += n as u64;
7070
if n == 0 {
7171
break;
7272
}
73-
try!(cb(Event::DownloadDataReceived(&buf[..n])));
73+
cb(Event::DownloadDataReceived(&buf[..n]))?;
7474
}
7575

7676
downloaded_so_far
7777
} else {
78-
let file_info = try!(partial.metadata());
78+
let file_info = partial.metadata()?;
7979
file_info.len()
8080
}
8181
} else {
8282
0
8383
};
8484

85-
let mut possible_partial = try!(
86-
OpenOptions::new()
87-
.write(true)
88-
.create(true)
89-
.open(&path)
90-
.chain_err(|| "error opening file for download")
91-
);
85+
let mut possible_partial = OpenOptions::new()
86+
.write(true)
87+
.create(true)
88+
.open(&path)
89+
.chain_err(|| "error opening file for download")?;
9290

93-
try!(possible_partial.seek(SeekFrom::End(0)));
91+
possible_partial.seek(SeekFrom::End(0))?;
9492

9593
(possible_partial, downloaded_so_far)
9694
} else {
9795
(
98-
try!(
99-
OpenOptions::new()
100-
.write(true)
101-
.create(true)
102-
.open(&path)
103-
.chain_err(|| "error creating file for download")
104-
),
96+
OpenOptions::new()
97+
.write(true)
98+
.create(true)
99+
.open(&path)
100+
.chain_err(|| "error creating file for download")?,
105101
0,
106102
)
107103
};
108104

109105
let file = RefCell::new(file);
110106

111-
try!(download_with_backend(backend, url, resume_from, &|event| {
107+
download_with_backend(backend, url, resume_from, &|event| {
112108
if let Event::DownloadDataReceived(data) = event {
113-
try!(
114-
file.borrow_mut()
115-
.write_all(data)
116-
.chain_err(|| "unable to write download to disk")
117-
);
109+
file.borrow_mut()
110+
.write_all(data)
111+
.chain_err(|| "unable to write download to disk")?;
118112
}
119113
match callback {
120114
Some(cb) => cb(event),
121115
None => Ok(()),
122116
}
123-
}));
117+
})?;
124118

125-
try!(
126-
file.borrow_mut()
127-
.sync_data()
128-
.chain_err(|| "unable to sync download to disk")
129-
);
119+
file.borrow_mut()
120+
.sync_data()
121+
.chain_err(|| "unable to sync download to disk")?;
130122

131123
Ok(())
132124
}()
@@ -161,35 +153,27 @@ pub mod curl {
161153
EASY.with(|handle| {
162154
let mut handle = handle.borrow_mut();
163155

164-
try!(
165-
handle
166-
.url(&url.to_string())
167-
.chain_err(|| "failed to set url")
168-
);
169-
try!(
170-
handle
171-
.follow_location(true)
172-
.chain_err(|| "failed to set follow redirects")
173-
);
156+
handle
157+
.url(&url.to_string())
158+
.chain_err(|| "failed to set url")?;
159+
handle
160+
.follow_location(true)
161+
.chain_err(|| "failed to set follow redirects")?;
174162

175163
if resume_from > 0 {
176-
try!(
177-
handle
178-
.resume_from(resume_from)
179-
.chain_err(|| "setting the range header for download resumption")
180-
);
164+
handle
165+
.resume_from(resume_from)
166+
.chain_err(|| "setting the range header for download resumption")?;
181167
} else {
182168
// an error here indicates that the range header isn't supported by underlying curl,
183169
// so there's nothing to "clear" - safe to ignore this error.
184170
let _ = handle.resume_from(0);
185171
}
186172

187173
// Take at most 30s to connect
188-
try!(
189-
handle
190-
.connect_timeout(Duration::new(30, 0))
191-
.chain_err(|| "failed to set connect timeout")
192-
);
174+
handle
175+
.connect_timeout(Duration::new(30, 0))
176+
.chain_err(|| "failed to set connect timeout")?;
193177

194178
{
195179
let cberr = RefCell::new(None);
@@ -198,47 +182,42 @@ pub mod curl {
198182
// Data callback for libcurl which is called with data that's
199183
// downloaded. We just feed it into our hasher and also write it out
200184
// to disk.
201-
try!(
202-
transfer
203-
.write_function(|data| match callback(Event::DownloadDataReceived(data)) {
204-
Ok(()) => Ok(data.len()),
205-
Err(e) => {
206-
*cberr.borrow_mut() = Some(e);
207-
Ok(0)
208-
}
209-
})
210-
.chain_err(|| "failed to set write")
211-
);
185+
transfer
186+
.write_function(|data| match callback(Event::DownloadDataReceived(data)) {
187+
Ok(()) => Ok(data.len()),
188+
Err(e) => {
189+
*cberr.borrow_mut() = Some(e);
190+
Ok(0)
191+
}
192+
})
193+
.chain_err(|| "failed to set write")?;
212194

213195
// Listen for headers and parse out a `Content-Length` if it comes
214196
// so we know how much we're downloading.
215-
try!(
216-
transfer
217-
.header_function(|header| {
218-
if let Ok(data) = str::from_utf8(header) {
219-
let prefix = "Content-Length: ";
220-
if data.starts_with(prefix) {
221-
if let Ok(s) = data[prefix.len()..].trim().parse::<u64>() {
222-
let msg =
223-
Event::DownloadContentLengthReceived(s + resume_from);
224-
match callback(msg) {
225-
Ok(()) => (),
226-
Err(e) => {
227-
*cberr.borrow_mut() = Some(e);
228-
return false;
229-
}
197+
transfer
198+
.header_function(|header| {
199+
if let Ok(data) = str::from_utf8(header) {
200+
let prefix = "Content-Length: ";
201+
if data.starts_with(prefix) {
202+
if let Ok(s) = data[prefix.len()..].trim().parse::<u64>() {
203+
let msg = Event::DownloadContentLengthReceived(s + resume_from);
204+
match callback(msg) {
205+
Ok(()) => (),
206+
Err(e) => {
207+
*cberr.borrow_mut() = Some(e);
208+
return false;
230209
}
231210
}
232211
}
233212
}
234-
true
235-
})
236-
.chain_err(|| "failed to set header")
237-
);
213+
}
214+
true
215+
})
216+
.chain_err(|| "failed to set header")?;
238217

239218
// If an error happens check to see if we had a filesystem error up
240219
// in `cberr`, but we always want to punt it up.
241-
try!(transfer.perform().or_else(|e| {
220+
transfer.perform().or_else(|e| {
242221
// If the original error was generated by one of our
243222
// callbacks, return it.
244223
match cberr.borrow_mut().take() {
@@ -252,15 +231,13 @@ pub mod curl {
252231
}
253232
}
254233
}
255-
}));
234+
})?;
256235
}
257236

258237
// If we didn't get a 20x or 0 ("OK" for files) then return an error
259-
let code = try!(
260-
handle
261-
.response_code()
262-
.chain_err(|| "failed to get response code")
263-
);
238+
let code = handle
239+
.response_code()
240+
.chain_err(|| "failed to get response code")?;
264241
match code {
265242
0 | 200...299 => {}
266243
_ => {
@@ -362,10 +339,8 @@ pub mod reqwest_be {
362339

363340
// The file scheme is mostly for use by tests to mock the dist server
364341
if url.scheme() == "file" {
365-
let src = try!(
366-
url.to_file_path()
367-
.map_err(|_| Error::from(format!("bogus file url: '{}'", url)))
368-
);
342+
let src = url.to_file_path()
343+
.map_err(|_| Error::from(format!("bogus file url: '{}'", url)))?;
369344
if !src.is_file() {
370345
// Because some of rustup's logic depends on checking
371346
// the error when a downloaded file doesn't exist, make
@@ -374,20 +349,17 @@ pub mod reqwest_be {
374349
return Err(ErrorKind::FileNotFound.into());
375350
}
376351

377-
let ref mut f =
378-
try!(fs::File::open(src).chain_err(|| "unable to open downloaded file"));
352+
let ref mut f = fs::File::open(src).chain_err(|| "unable to open downloaded file")?;
379353
io::Seek::seek(f, io::SeekFrom::Start(resume_from))?;
380354

381355
let ref mut buffer = vec![0u8; 0x10000];
382356
loop {
383357
let bytes_read =
384-
try!(io::Read::read(f, buffer).chain_err(|| "unable to read downloaded file"));
358+
io::Read::read(f, buffer).chain_err(|| "unable to read downloaded file")?;
385359
if bytes_read == 0 {
386360
break;
387361
}
388-
try!(callback(Event::DownloadDataReceived(
389-
&buffer[0..bytes_read]
390-
)));
362+
callback(Event::DownloadDataReceived(&buffer[0..bytes_read]))?;
391363
}
392364

393365
Ok(true)

src/rustup-cli/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ error_chain! {
2727
description("toolchain is not installed")
2828
display("toolchain '{}' is not installed", t)
2929
}
30+
InvalidToolchainName(t: String) {
31+
description("invalid toolchain name")
32+
display("invalid toolchain name: '{}'", t)
33+
}
3034
InfiniteRecursion {
3135
description("infinite recursion detected")
3236
}

src/rustup-cli/help.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ r"DISCUSSION:
234234
235235
Now open the file provided by `$profile` (if you used the
236236
`New-Item` command it will be
237-
`%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1`
237+
`${env:USERPROFILE}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1`
238238
239239
Next, we either save the completions file into our profile, or
240240
into a separate file and source it inside our profile. To save the
241241
completions into our profile simply use
242242
243-
PS C:\> rustup completions powershell >> %USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1";
243+
PS C:\> rustup completions powershell >> ${env:USERPROFILE}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1";
244244

245245
pub static TOOLCHAIN_ARG_HELP: &'static str = "Toolchain name, such as 'stable', 'nightly', \
246246
or '1.8.0'. For more information see `rustup \

src/rustup-cli/rustup_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
558558
let status = if !toolchain.is_custom() {
559559
Some(try!(toolchain.install_from_dist(m.is_present("force"))))
560560
} else if !toolchain.exists() {
561-
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
561+
return Err(ErrorKind::InvalidToolchainName(toolchain.name().to_string()).into());
562562
} else {
563563
None
564564
};

src/rustup-cli/self_update.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -302,30 +302,29 @@ pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result<
302302
process::exit(1);
303303
}
304304

305-
// More helpful advice, skip if -y
306-
if !no_prompt {
307-
let cargo_home = try!(canonical_cargo_home());
308-
let msg = if !opts.no_modify_path {
309-
if cfg!(unix) {
310-
format!(post_install_msg_unix!(), cargo_home = cargo_home)
311-
} else {
312-
format!(post_install_msg_win!(), cargo_home = cargo_home)
313-
}
305+
let cargo_home = try!(canonical_cargo_home());
306+
let msg = if !opts.no_modify_path {
307+
if cfg!(unix) {
308+
format!(post_install_msg_unix!(), cargo_home = cargo_home)
314309
} else {
315-
if cfg!(unix) {
316-
format!(
317-
post_install_msg_unix_no_modify_path!(),
318-
cargo_home = cargo_home
319-
)
320-
} else {
321-
format!(
322-
post_install_msg_win_no_modify_path!(),
323-
cargo_home = cargo_home
324-
)
325-
}
326-
};
327-
term2::stdout().md(msg);
310+
format!(post_install_msg_win!(), cargo_home = cargo_home)
311+
}
312+
} else {
313+
if cfg!(unix) {
314+
format!(
315+
post_install_msg_unix_no_modify_path!(),
316+
cargo_home = cargo_home
317+
)
318+
} else {
319+
format!(
320+
post_install_msg_win_no_modify_path!(),
321+
cargo_home = cargo_home
322+
)
323+
}
324+
};
325+
term2::stdout().md(msg);
328326

327+
if !no_prompt {
329328
// On windows, where installation happens in a console
330329
// that may have opened just for this purpose, require
331330
// the user to press a key to continue.

0 commit comments

Comments
 (0)