Skip to content

Commit ccdc47b

Browse files
authored
Merge pull request #88 from h-michael/2018-edition
Transition to 2018 edition
2 parents 27dec6c + 2454b52 commit ccdc47b

9 files changed

+49
-53
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = ["The Rust Project Developers"]
33
name = "installer"
44
version = "0.0.0"
5+
edition = "2018"
56

67
[[bin]]
78
doc = false

src/combiner.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use std::path::Path;
1313
use flate2::read::GzDecoder;
1414
use tar::Archive;
1515

16-
use errors::*;
16+
use crate::errors::*;
1717
use super::Scripter;
1818
use super::Tarballer;
19-
use util::*;
19+
use crate::util::*;
2020

2121
actor!{
2222
#[derive(Debug)]
@@ -70,7 +70,7 @@ impl Combiner {
7070
.chain_err(|| format!("unable to extract '{}' into '{}'",
7171
&input_tarball, self.work_dir))?;
7272

73-
let pkg_name = input_tarball.trim_right_matches(".tar.gz");
73+
let pkg_name = input_tarball.trim_end_matches(".tar.gz");
7474
let pkg_name = Path::new(pkg_name).file_name().unwrap();
7575
let pkg_dir = Path::new(&self.work_dir).join(&pkg_name);
7676

@@ -79,7 +79,7 @@ impl Combiner {
7979
open_file(pkg_dir.join("rust-installer-version"))
8080
.and_then(|mut file| file.read_to_string(&mut version).map_err(Error::from))
8181
.chain_err(|| format!("failed to read version in '{}'", input_tarball))?;
82-
if version.trim().parse() != Ok(::RUST_INSTALLER_VERSION) {
82+
if version.trim().parse() != Ok(crate::RUST_INSTALLER_VERSION) {
8383
bail!("incorrect installer version in {}", input_tarball);
8484
}
8585

@@ -105,7 +105,7 @@ impl Combiner {
105105

106106
// Write the installer version
107107
let version = package_dir.join("rust-installer-version");
108-
writeln!(create_new_file(version)?, "{}", ::RUST_INSTALLER_VERSION)
108+
writeln!(create_new_file(version)?, "{}", crate::RUST_INSTALLER_VERSION)
109109
.chain_err(|| "failed to write new installer version")?;
110110

111111
// Copy the overlay

src/generator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use std::io::Write;
1212
use std::path::Path;
1313

14-
use errors::*;
14+
use crate::errors::*;
1515
use super::Scripter;
1616
use super::Tarballer;
17-
use util::*;
17+
use crate::util::*;
1818

1919
actor!{
2020
#[derive(Debug)]
@@ -76,7 +76,7 @@ impl Generator {
7676

7777
// Write the installer version (only used by combine-installers.sh)
7878
let version = package_dir.join("rust-installer-version");
79-
writeln!(create_new_file(version)?, "{}", ::RUST_INSTALLER_VERSION)
79+
writeln!(create_new_file(version)?, "{}", crate::RUST_INSTALLER_VERSION)
8080
.chain_err(|| "failed to write new installer version")?;
8181

8282
// Copy the overlay

src/lib.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
#[macro_use]
1212
extern crate error_chain;
13-
extern crate flate2;
14-
extern crate rayon;
15-
extern crate tar;
16-
extern crate walkdir;
17-
extern crate xz2;
1813

1914
#[cfg(windows)]
2015
extern crate winapi;
@@ -43,11 +38,11 @@ mod generator;
4338
mod scripter;
4439
mod tarballer;
4540

46-
pub use errors::{Result, Error, ErrorKind};
47-
pub use combiner::Combiner;
48-
pub use generator::Generator;
49-
pub use scripter::Scripter;
50-
pub use tarballer::Tarballer;
41+
pub use crate::errors::{Result, Error, ErrorKind};
42+
pub use crate::combiner::Combiner;
43+
pub use crate::generator::Generator;
44+
pub use crate::scripter::Scripter;
45+
pub use crate::tarballer::Tarballer;
5146

5247
/// The installer version, output only to be used by combine-installers.sh.
5348
/// (should match `SOURCE_DIRECTORY/rust_installer_version`)

src/main.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
extern crate clap;
33
#[macro_use]
44
extern crate error_chain;
5-
extern crate installer;
5+
use installer;
66

7-
use errors::*;
7+
use crate::errors::*;
88
use clap::{App, ArgMatches};
99

1010
mod errors {
@@ -41,7 +41,7 @@ macro_rules! parse(
4141
}
4242
);
4343

44-
fn combine(matches: &ArgMatches) -> Result<()> {
44+
fn combine(matches: &ArgMatches<'_>) -> Result<()> {
4545
let combiner = parse!(matches => installer::Combiner {
4646
"product-name" => product_name,
4747
"package-name" => package_name,
@@ -57,7 +57,7 @@ fn combine(matches: &ArgMatches) -> Result<()> {
5757
combiner.run().chain_err(|| "failed to combine installers")
5858
}
5959

60-
fn generate(matches: &ArgMatches) -> Result<()> {
60+
fn generate(matches: &ArgMatches<'_>) -> Result<()> {
6161
let generator = parse!(matches => installer::Generator {
6262
"product-name" => product_name,
6363
"component-name" => component_name,
@@ -75,7 +75,7 @@ fn generate(matches: &ArgMatches) -> Result<()> {
7575
generator.run().chain_err(|| "failed to generate installer")
7676
}
7777

78-
fn script(matches: &ArgMatches) -> Result<()> {
78+
fn script(matches: &ArgMatches<'_>) -> Result<()> {
7979
let scripter = parse!(matches => installer::Scripter {
8080
"product-name" => product_name,
8181
"rel-manifest-dir" => rel_manifest_dir,
@@ -87,7 +87,7 @@ fn script(matches: &ArgMatches) -> Result<()> {
8787
scripter.run().chain_err(|| "failed to generate installation script")
8888
}
8989

90-
fn tarball(matches: &ArgMatches) -> Result<()> {
90+
fn tarball(matches: &ArgMatches<'_>) -> Result<()> {
9191
let tarballer = parse!(matches => installer::Tarballer {
9292
"input" => input,
9393
"output" => output,

src/remove_dir_all.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ mod win {
103103
opts.access_mode(FILE_READ_ATTRIBUTES);
104104
opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS |
105105
FILE_FLAG_OPEN_REPARSE_POINT);
106-
let file = try!(File::open(path, &opts));
107-
(try!(get_path(&file)), try!(file.file_attr()))
106+
let file = r#try!(File::open(path, &opts));
107+
(r#try!(get_path(&file)), r#try!(file.file_attr()))
108108
};
109109

110110
let mut ctx = RmdirContext {
@@ -131,7 +131,7 @@ mod win {
131131
fn readdir(p: &Path) -> io::Result<ReadDir> {
132132
let root = p.to_path_buf();
133133
let star = p.join("*");
134-
let path = try!(to_u16s(&star));
134+
let path = r#try!(to_u16s(&star));
135135

136136
unsafe {
137137
let mut wfd = mem::zeroed();
@@ -157,14 +157,14 @@ mod win {
157157
fn remove_dir_all_recursive(path: &Path, ctx: &mut RmdirContext)
158158
-> io::Result<()> {
159159
let dir_readonly = ctx.readonly;
160-
for child in try!(readdir(path)) {
161-
let child = try!(child);
162-
let child_type = try!(child.file_type());
163-
ctx.readonly = try!(child.metadata()).perm().readonly();
160+
for child in r#try!(readdir(path)) {
161+
let child = r#try!(child);
162+
let child_type = r#try!(child.file_type());
163+
ctx.readonly = r#try!(child.metadata()).perm().readonly();
164164
if child_type.is_dir() {
165-
try!(remove_dir_all_recursive(&child.path(), ctx));
165+
r#try!(remove_dir_all_recursive(&child.path(), ctx));
166166
} else {
167-
try!(remove_item(&child.path().as_ref(), ctx));
167+
r#try!(remove_item(&child.path().as_ref(), ctx));
168168
}
169169
}
170170
ctx.readonly = dir_readonly;
@@ -178,20 +178,20 @@ mod win {
178178
opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS | // delete directory
179179
FILE_FLAG_OPEN_REPARSE_POINT | // delete symlink
180180
FILE_FLAG_DELETE_ON_CLOSE);
181-
let file = try!(File::open(path, &opts));
181+
let file = r#try!(File::open(path, &opts));
182182
move_item(&file, ctx)
183183
} else {
184184
// remove read-only permision
185-
try!(set_perm(&path, FilePermissions::new()));
185+
r#try!(set_perm(&path, FilePermissions::new()));
186186
// move and delete file, similar to !readonly.
187187
// only the access mode is different.
188188
let mut opts = OpenOptions::new();
189189
opts.access_mode(DELETE | FILE_WRITE_ATTRIBUTES);
190190
opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS |
191191
FILE_FLAG_OPEN_REPARSE_POINT |
192192
FILE_FLAG_DELETE_ON_CLOSE);
193-
let file = try!(File::open(path, &opts));
194-
try!(move_item(&file, ctx));
193+
let file = r#try!(File::open(path, &opts));
194+
r#try!(move_item(&file, ctx));
195195
// restore read-only flag just in case there are other hard links
196196
let mut perm = FilePermissions::new();
197197
perm.set_readonly(true);
@@ -445,13 +445,13 @@ mod win {
445445

446446
impl File {
447447
fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
448-
let path = try!(to_u16s(path));
448+
let path = r#try!(to_u16s(path));
449449
let handle = unsafe {
450450
CreateFileW(path.as_ptr(),
451-
try!(opts.get_access_mode()),
451+
r#try!(opts.get_access_mode()),
452452
opts.share_mode,
453453
opts.security_attributes as *mut _,
454-
try!(opts.get_creation_mode()),
454+
r#try!(opts.get_creation_mode()),
455455
opts.get_flags_and_attributes(),
456456
ptr::null_mut())
457457
};
@@ -465,7 +465,7 @@ mod win {
465465
fn file_attr(&self) -> io::Result<FileAttr> {
466466
unsafe {
467467
let mut info: BY_HANDLE_FILE_INFORMATION = mem::zeroed();
468-
try!(cvt(GetFileInformationByHandle(self.handle.raw(),
468+
r#try!(cvt(GetFileInformationByHandle(self.handle.raw(),
469469
&mut info)));
470470
let mut attr = FileAttr {
471471
attributes: info.dwFileAttributes,
@@ -498,7 +498,7 @@ mod win {
498498
FileAttributes: attr,
499499
};
500500
let size = mem::size_of_val(&info);
501-
try!(cvt(unsafe {
501+
r#try!(cvt(unsafe {
502502
SetFileInformationByHandle(self.handle.raw(),
503503
FileBasicInfo,
504504
&mut info as *mut _ as *mut _,
@@ -531,15 +531,15 @@ mod win {
531531
(*info).ReplaceIfExists = if replace { -1 } else { FALSE };
532532
(*info).RootDirectory = ptr::null_mut();
533533
(*info).FileNameLength = (size - STRUCT_SIZE) as DWORD;
534-
try!(cvt(SetFileInformationByHandle(self.handle().raw(),
534+
r#try!(cvt(SetFileInformationByHandle(self.handle().raw(),
535535
FileRenameInfo,
536536
data.as_mut_ptr() as *mut _ as *mut _,
537537
size as DWORD)));
538538
Ok(())
539539
}
540540
}
541541
fn set_perm(&self, perm: FilePermissions) -> io::Result<()> {
542-
let attr = try!(self.file_attr()).attributes;
542+
let attr = r#try!(self.file_attr()).attributes;
543543
if perm.readonly == (attr & FILE_ATTRIBUTE_READONLY != 0) {
544544
Ok(())
545545
} else if perm.readonly {
@@ -556,7 +556,7 @@ mod win {
556556
-> io::Result<(DWORD, &'a REPARSE_DATA_BUFFER)> {
557557
unsafe {
558558
let mut bytes = 0;
559-
try!(cvt({
559+
r#try!(cvt({
560560
DeviceIoControl(self.handle.raw(),
561561
FSCTL_GET_REPARSE_POINT,
562562
ptr::null_mut(),
@@ -792,7 +792,7 @@ mod win {
792792
let mut opts = OpenOptions::new();
793793
opts.access_mode(FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES);
794794
opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS);
795-
let file = try!(File::open(path, &opts));
795+
let file = r#try!(File::open(path, &opts));
796796
file.set_perm(perm)
797797
}
798798

src/scripter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
use std::io::Write;
1212

13-
use errors::*;
14-
use util::*;
13+
use crate::errors::*;
14+
use crate::util::*;
1515

1616
const TEMPLATE: &'static str = include_str!("../install-template.sh");
1717

@@ -52,7 +52,7 @@ impl Scripter {
5252
.replace("%%TEMPLATE_REL_MANIFEST_DIR%%", &self.rel_manifest_dir)
5353
.replace("%%TEMPLATE_SUCCESS_MESSAGE%%", &sh_quote(&success_message))
5454
.replace("%%TEMPLATE_LEGACY_MANIFEST_DIRS%%", &sh_quote(&self.legacy_manifest_dirs))
55-
.replace("%%TEMPLATE_RUST_INSTALLER_VERSION%%", &sh_quote(&::RUST_INSTALLER_VERSION));
55+
.replace("%%TEMPLATE_RUST_INSTALLER_VERSION%%", &sh_quote(&crate::RUST_INSTALLER_VERSION));
5656

5757
create_new_executable(&self.output_script)?
5858
.write_all(script.as_ref())

src/tarballer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use tar::{Builder, Header};
1919
use walkdir::WalkDir;
2020
use xz2::write::XzEncoder;
2121

22-
use errors::*;
23-
use util::*;
22+
use crate::errors::*;
23+
use crate::util::*;
2424

2525
actor!{
2626
#[derive(Debug)]

src/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::os::unix::fs::symlink as symlink_file;
2323
#[cfg(windows)]
2424
use std::os::windows::fs::symlink_file;
2525

26-
use errors::*;
26+
use crate::errors::*;
2727

2828
/// Convert a `&Path` to a UTF-8 `&str`
2929
pub fn path_to_str(path: &Path) -> Result<&str> {
@@ -80,7 +80,7 @@ pub fn open_file<P: AsRef<Path>>(path: P) -> Result<fs::File> {
8080

8181
/// Wrap `remove_dir_all` with a nicer error message
8282
pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
83-
::remove_dir_all::remove_dir_all(path.as_ref())
83+
crate::remove_dir_all::remove_dir_all(path.as_ref())
8484
.chain_err(|| format!("failed to remove dir '{}'", path.as_ref().display()))
8585
}
8686

0 commit comments

Comments
 (0)