Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to 2018 edition #88

Merged
merged 2 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "installer"
version = "0.0.0"
edition = "2018"

[[bin]]
doc = false
Expand Down
10 changes: 5 additions & 5 deletions src/combiner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use std::path::Path;
use flate2::read::GzDecoder;
use tar::Archive;

use errors::*;
use crate::errors::*;
use super::Scripter;
use super::Tarballer;
use util::*;
use crate::util::*;

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

let pkg_name = input_tarball.trim_right_matches(".tar.gz");
let pkg_name = input_tarball.trim_end_matches(".tar.gz");
let pkg_name = Path::new(pkg_name).file_name().unwrap();
let pkg_dir = Path::new(&self.work_dir).join(&pkg_name);

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

Expand All @@ -105,7 +105,7 @@ impl Combiner {

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

// Copy the overlay
Expand Down
6 changes: 3 additions & 3 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
use std::io::Write;
use std::path::Path;

use errors::*;
use crate::errors::*;
use super::Scripter;
use super::Tarballer;
use util::*;
use crate::util::*;

actor!{
#[derive(Debug)]
Expand Down Expand Up @@ -76,7 +76,7 @@ impl Generator {

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

// Copy the overlay
Expand Down
15 changes: 5 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

#[macro_use]
extern crate error_chain;
extern crate flate2;
extern crate rayon;
extern crate tar;
extern crate walkdir;
extern crate xz2;

#[cfg(windows)]
extern crate winapi;
Expand Down Expand Up @@ -43,11 +38,11 @@ mod generator;
mod scripter;
mod tarballer;

pub use errors::{Result, Error, ErrorKind};
pub use combiner::Combiner;
pub use generator::Generator;
pub use scripter::Scripter;
pub use tarballer::Tarballer;
pub use crate::errors::{Result, Error, ErrorKind};
pub use crate::combiner::Combiner;
pub use crate::generator::Generator;
pub use crate::scripter::Scripter;
pub use crate::tarballer::Tarballer;

/// The installer version, output only to be used by combine-installers.sh.
/// (should match `SOURCE_DIRECTORY/rust_installer_version`)
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
extern crate clap;
#[macro_use]
extern crate error_chain;
extern crate installer;
use installer;

use errors::*;
use crate::errors::*;
use clap::{App, ArgMatches};

mod errors {
Expand Down Expand Up @@ -41,7 +41,7 @@ macro_rules! parse(
}
);

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

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

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

fn tarball(matches: &ArgMatches) -> Result<()> {
fn tarball(matches: &ArgMatches<'_>) -> Result<()> {
let tarballer = parse!(matches => installer::Tarballer {
"input" => input,
"output" => output,
Expand Down
44 changes: 22 additions & 22 deletions src/remove_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ mod win {
opts.access_mode(FILE_READ_ATTRIBUTES);
opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS |
FILE_FLAG_OPEN_REPARSE_POINT);
let file = try!(File::open(path, &opts));
(try!(get_path(&file)), try!(file.file_attr()))
let file = r#try!(File::open(path, &opts));
(r#try!(get_path(&file)), r#try!(file.file_attr()))
};

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

unsafe {
let mut wfd = mem::zeroed();
Expand All @@ -157,14 +157,14 @@ mod win {
fn remove_dir_all_recursive(path: &Path, ctx: &mut RmdirContext)
-> io::Result<()> {
let dir_readonly = ctx.readonly;
for child in try!(readdir(path)) {
let child = try!(child);
let child_type = try!(child.file_type());
ctx.readonly = try!(child.metadata()).perm().readonly();
for child in r#try!(readdir(path)) {
let child = r#try!(child);
let child_type = r#try!(child.file_type());
ctx.readonly = r#try!(child.metadata()).perm().readonly();
if child_type.is_dir() {
try!(remove_dir_all_recursive(&child.path(), ctx));
r#try!(remove_dir_all_recursive(&child.path(), ctx));
} else {
try!(remove_item(&child.path().as_ref(), ctx));
r#try!(remove_item(&child.path().as_ref(), ctx));
}
}
ctx.readonly = dir_readonly;
Expand All @@ -178,20 +178,20 @@ mod win {
opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS | // delete directory
FILE_FLAG_OPEN_REPARSE_POINT | // delete symlink
FILE_FLAG_DELETE_ON_CLOSE);
let file = try!(File::open(path, &opts));
let file = r#try!(File::open(path, &opts));
move_item(&file, ctx)
} else {
// remove read-only permision
try!(set_perm(&path, FilePermissions::new()));
r#try!(set_perm(&path, FilePermissions::new()));
// move and delete file, similar to !readonly.
// only the access mode is different.
let mut opts = OpenOptions::new();
opts.access_mode(DELETE | FILE_WRITE_ATTRIBUTES);
opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS |
FILE_FLAG_OPEN_REPARSE_POINT |
FILE_FLAG_DELETE_ON_CLOSE);
let file = try!(File::open(path, &opts));
try!(move_item(&file, ctx));
let file = r#try!(File::open(path, &opts));
r#try!(move_item(&file, ctx));
// restore read-only flag just in case there are other hard links
let mut perm = FilePermissions::new();
perm.set_readonly(true);
Expand Down Expand Up @@ -445,13 +445,13 @@ mod win {

impl File {
fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
let path = try!(to_u16s(path));
let path = r#try!(to_u16s(path));
let handle = unsafe {
CreateFileW(path.as_ptr(),
try!(opts.get_access_mode()),
r#try!(opts.get_access_mode()),
opts.share_mode,
opts.security_attributes as *mut _,
try!(opts.get_creation_mode()),
r#try!(opts.get_creation_mode()),
opts.get_flags_and_attributes(),
ptr::null_mut())
};
Expand All @@ -465,7 +465,7 @@ mod win {
fn file_attr(&self) -> io::Result<FileAttr> {
unsafe {
let mut info: BY_HANDLE_FILE_INFORMATION = mem::zeroed();
try!(cvt(GetFileInformationByHandle(self.handle.raw(),
r#try!(cvt(GetFileInformationByHandle(self.handle.raw(),
&mut info)));
let mut attr = FileAttr {
attributes: info.dwFileAttributes,
Expand Down Expand Up @@ -498,7 +498,7 @@ mod win {
FileAttributes: attr,
};
let size = mem::size_of_val(&info);
try!(cvt(unsafe {
r#try!(cvt(unsafe {
SetFileInformationByHandle(self.handle.raw(),
FileBasicInfo,
&mut info as *mut _ as *mut _,
Expand Down Expand Up @@ -531,15 +531,15 @@ mod win {
(*info).ReplaceIfExists = if replace { -1 } else { FALSE };
(*info).RootDirectory = ptr::null_mut();
(*info).FileNameLength = (size - STRUCT_SIZE) as DWORD;
try!(cvt(SetFileInformationByHandle(self.handle().raw(),
r#try!(cvt(SetFileInformationByHandle(self.handle().raw(),
FileRenameInfo,
data.as_mut_ptr() as *mut _ as *mut _,
size as DWORD)));
Ok(())
}
}
fn set_perm(&self, perm: FilePermissions) -> io::Result<()> {
let attr = try!(self.file_attr()).attributes;
let attr = r#try!(self.file_attr()).attributes;
if perm.readonly == (attr & FILE_ATTRIBUTE_READONLY != 0) {
Ok(())
} else if perm.readonly {
Expand All @@ -556,7 +556,7 @@ mod win {
-> io::Result<(DWORD, &'a REPARSE_DATA_BUFFER)> {
unsafe {
let mut bytes = 0;
try!(cvt({
r#try!(cvt({
DeviceIoControl(self.handle.raw(),
FSCTL_GET_REPARSE_POINT,
ptr::null_mut(),
Expand Down Expand Up @@ -792,7 +792,7 @@ mod win {
let mut opts = OpenOptions::new();
opts.access_mode(FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES);
opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS);
let file = try!(File::open(path, &opts));
let file = r#try!(File::open(path, &opts));
file.set_perm(perm)
}

Expand Down
6 changes: 3 additions & 3 deletions src/scripter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

use std::io::Write;

use errors::*;
use util::*;
use crate::errors::*;
use crate::util::*;

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

Expand Down Expand Up @@ -52,7 +52,7 @@ impl Scripter {
.replace("%%TEMPLATE_REL_MANIFEST_DIR%%", &self.rel_manifest_dir)
.replace("%%TEMPLATE_SUCCESS_MESSAGE%%", &sh_quote(&success_message))
.replace("%%TEMPLATE_LEGACY_MANIFEST_DIRS%%", &sh_quote(&self.legacy_manifest_dirs))
.replace("%%TEMPLATE_RUST_INSTALLER_VERSION%%", &sh_quote(&::RUST_INSTALLER_VERSION));
.replace("%%TEMPLATE_RUST_INSTALLER_VERSION%%", &sh_quote(&crate::RUST_INSTALLER_VERSION));

create_new_executable(&self.output_script)?
.write_all(script.as_ref())
Expand Down
4 changes: 2 additions & 2 deletions src/tarballer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use tar::{Builder, Header};
use walkdir::WalkDir;
use xz2::write::XzEncoder;

use errors::*;
use util::*;
use crate::errors::*;
use crate::util::*;

actor!{
#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::os::unix::fs::symlink as symlink_file;
#[cfg(windows)]
use std::os::windows::fs::symlink_file;

use errors::*;
use crate::errors::*;

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

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

Expand Down