summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2019-02-19 09:40:17 -0600
committerGitHub <noreply@github.com>2019-02-19 09:40:17 -0600
commit5afc0089f282570f2c39b4345d2706bf97e3d84b (patch)
treee807d9bd7da30e10e3145728327b98ddf090f915
parentded5704f82c351217e83553587daec4345d0c0d6 (diff)
parent0fe48c3c21bb0def214a72758a91cd7747aaea1e (diff)
downloadrust-installer-5afc0089f282570f2c39b4345d2706bf97e3d84b.tar.gz
Merge pull request #90 from alexreg/cosmetic-2
Various cosmetic improvements
-rw-r--r--src/combiner.rs51
-rw-r--r--src/generator.rs12
-rw-r--r--src/lib.rs10
-rw-r--r--src/remove_dir_all.rs12
-rw-r--r--src/scripter.rs16
-rw-r--r--src/tarballer.rs32
-rw-r--r--src/util.rs32
7 files changed, 48 insertions, 117 deletions
diff --git a/src/combiner.rs b/src/combiner.rs
index 222e62c..2d22992 100644
--- a/src/combiner.rs
+++ b/src/combiner.rs
@@ -1,57 +1,48 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
use std::io::{Read, Write};
use std::path::Path;
+
use flate2::read::GzDecoder;
use tar::Archive;
use crate::errors::*;
+use crate::util::*;
use super::Scripter;
use super::Tarballer;
-use crate::util::*;
actor!{
#[derive(Debug)]
pub struct Combiner {
- /// The name of the product, for display
+ /// The name of the product, for display.
product_name: String = "Product",
- /// The name of the package, tarball
+ /// The name of the package tarball.
package_name: String = "package",
- /// The directory under lib/ where the manifest lives
+ /// The directory under lib/ where the manifest lives.
rel_manifest_dir: String = "packagelib",
- /// The string to print after successful installation
+ /// The string to print after successful installation.
success_message: String = "Installed.",
- /// Places to look for legacy manifests to uninstall
+ /// Places to look for legacy manifests to uninstall.
legacy_manifest_dirs: String = "",
- /// Installers to combine
+ /// Installers to combine.
input_tarballs: String = "",
- /// Directory containing files that should not be installed
+ /// Directory containing files that should not be installed.
non_installed_overlay: String = "",
- /// The directory to do temporary work
+ /// The directory to do temporary work.
work_dir: String = "./workdir",
- /// The location to put the final image and tarball
+ /// The location to put the final image and tarball.
output_dir: String = "./dist",
}
}
impl Combiner {
- /// Combine the installer tarballs
+ /// Combines the installer tarballs.
pub fn run(self) -> Result<()> {
create_dir_all(&self.work_dir)?;
@@ -61,7 +52,7 @@ impl Combiner {
}
create_dir_all(&package_dir)?;
- // Merge each installer into the work directory of the new installer
+ // Merge each installer into the work directory of the new installer.
let components = create_new_file(package_dir.join("components"))?;
for input_tarball in self.input_tarballs.split(',').map(str::trim).filter(|s| !s.is_empty()) {
// Extract the input tarballs
@@ -74,7 +65,7 @@ impl Combiner {
let pkg_name = Path::new(pkg_name).file_name().unwrap();
let pkg_dir = Path::new(&self.work_dir).join(&pkg_name);
- // Verify the version number
+ // Verify the version number.
let mut version = String::new();
open_file(pkg_dir.join("rust-installer-version"))
.and_then(|mut file| file.read_to_string(&mut version).map_err(Error::from))
@@ -83,37 +74,37 @@ impl Combiner {
bail!("incorrect installer version in {}", input_tarball);
}
- // Copy components to the new combined installer
+ // Copy components to the new combined installer.
let mut pkg_components = String::new();
open_file(pkg_dir.join("components"))
.and_then(|mut file| file.read_to_string(&mut pkg_components).map_err(Error::from))
.chain_err(|| format!("failed to read components in '{}'", input_tarball))?;
for component in pkg_components.split_whitespace() {
- // All we need to do is copy the component directory. We could
+ // All we need to do is copy the component directory. We could
// move it, but rustbuild wants to reuse the unpacked package
// dir for OS-specific installers on macOS and Windows.
let component_dir = package_dir.join(&component);
create_dir(&component_dir)?;
copy_recursive(&pkg_dir.join(&component), &component_dir)?;
- // Merge the component name
+ // Merge the component name.
writeln!(&components, "{}", component)
.chain_err(|| "failed to write new components")?;
}
}
drop(components);
- // Write the installer version
+ // Write the installer version.
let version = package_dir.join("rust-installer-version");
writeln!(create_new_file(version)?, "{}", crate::RUST_INSTALLER_VERSION)
.chain_err(|| "failed to write new installer version")?;
- // Copy the overlay
+ // Copy the overlay.
if !self.non_installed_overlay.is_empty() {
copy_recursive(self.non_installed_overlay.as_ref(), &package_dir)?;
}
- // Generate the install script
+ // Generate the install script.
let output_script = package_dir.join("install.sh");
let mut scripter = Scripter::default();
scripter.product_name(self.product_name)
@@ -123,7 +114,7 @@ impl Combiner {
.output_script(path_to_str(&output_script)?);
scripter.run()?;
- // Make the tarballs
+ // Make the tarballs.
create_dir_all(&self.output_dir)?;
let output = Path::new(&self.output_dir).join(&self.package_name);
let mut tarballer = Tarballer::default();
diff --git a/src/generator.rs b/src/generator.rs
index 90d647e..60e54f2 100644
--- a/src/generator.rs
+++ b/src/generator.rs
@@ -1,13 +1,3 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
use std::io::Write;
use std::path::Path;
@@ -55,7 +45,7 @@ actor!{
}
impl Generator {
- /// Generate the actual installer tarball
+ /// Generates the actual installer tarball
pub fn run(self) -> Result<()> {
create_dir_all(&self.work_dir)?;
diff --git a/src/lib.rs b/src/lib.rs
index af302f1..a45d87c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,13 +1,3 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
#[macro_use]
extern crate error_chain;
diff --git a/src/remove_dir_all.rs b/src/remove_dir_all.rs
index e67079b..70c16a2 100644
--- a/src/remove_dir_all.rs
+++ b/src/remove_dir_all.rs
@@ -1,13 +1,3 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
#![allow(non_snake_case)]
use std::path::Path;
@@ -67,7 +57,7 @@ mod win {
// already need write permission in this dir to delete the directory. And it
// should be on the same volume.
//
- // To handle files with names like `CON` and `morse .. .`, and when a
+ // To handle files with names like `CON` and `morse .. .`, and when a
// directory structure is so deep it needs long path names the path is first
// converted to a `//?/`-path with `get_path()`.
//
diff --git a/src/scripter.rs b/src/scripter.rs
index 3b11efa..fae464c 100644
--- a/src/scripter.rs
+++ b/src/scripter.rs
@@ -1,13 +1,3 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
use std::io::Write;
use crate::errors::*;
@@ -37,14 +27,14 @@ actor!{
}
impl Scripter {
- /// Generate the actual installer script
+ /// Generates the actual installer script
pub fn run(self) -> Result<()> {
// Replace dashes in the success message with spaces (our arg handling botches spaces)
- // (TODO: still needed? kept for compatibility for now...)
+ // TODO: still needed? Kept for compatibility for now.
let product_name = self.product_name.replace('-', " ");
// Replace dashes in the success message with spaces (our arg handling botches spaces)
- // (TODO: still needed? kept for compatibility for now...)
+ // TODO: still needed? Kept for compatibility for now.
let success_message = self.success_message.replace('-', " ");
let script = TEMPLATE
diff --git a/src/tarballer.rs b/src/tarballer.rs
index 03c4729..9dfaa1c 100644
--- a/src/tarballer.rs
+++ b/src/tarballer.rs
@@ -1,13 +1,3 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
use std::fs::{read_link, symlink_metadata};
use std::io::{self, empty, Write, BufWriter};
use std::path::Path;
@@ -25,24 +15,24 @@ use crate::util::*;
actor!{
#[derive(Debug)]
pub struct Tarballer {
- /// The input folder to be compressed
+ /// The input folder to be compressed.
input: String = "package",
- /// The prefix of the tarballs
+ /// The prefix of the tarballs.
output: String = "./dist",
- /// The folder in which the input is to be found
+ /// The folder in which the input is to be found.
work_dir: String = "./workdir",
}
}
impl Tarballer {
- /// Generate the actual tarballs
+ /// Generates the actual tarballs
pub fn run(self) -> Result<()> {
let tar_gz = self.output.clone() + ".tar.gz";
let tar_xz = self.output.clone() + ".tar.xz";
- // Remove any existing files
+ // Remove any existing files.
for file in &[&tar_gz, &tar_xz] {
if Path::new(file).exists() {
remove_file(file)?;
@@ -56,14 +46,14 @@ impl Tarballer {
.chain_err(|| "failed to collect file paths")?;
files.sort_by(|a, b| a.bytes().rev().cmp(b.bytes().rev()));
- // Prepare the .tar.gz file
+ // Prepare the `.tar.gz` file.
let gz = GzEncoder::new(create_new_file(tar_gz)?, flate2::Compression::best());
- // Prepare the .tar.xz file
+ // Prepare the `.tar.xz` file.
let xz = XzEncoder::new(create_new_file(tar_xz)?, 6);
- // Write the tar into both encoded files. We write all directories
- // first, so files may be directly created. (see rustup.rs#1092)
+ // Write the tar into both encoded files. We write all directories
+ // first, so files may be directly created. (See rust-lang/rustup.rs#1092.)
let tee = RayonTee(xz, gz);
let buf = BufWriter::with_capacity(1024 * 1024, tee);
let mut builder = Builder::new(buf);
@@ -84,7 +74,7 @@ impl Tarballer {
.chain_err(|| "failed to finish writing .tar stream")?
.into_inner().ok().unwrap();
- // Finish both encoded files
+ // Finish both encoded files.
let (rxz, rgz) = rayon::join(
|| xz.finish().chain_err(|| "failed to finish .tar.xz file"),
|| gz.finish().chain_err(|| "failed to finish .tar.gz file"),
@@ -120,7 +110,7 @@ fn append_path<W: Write>(builder: &mut Builder<W>, src: &Path, path: &String) ->
Ok(())
}
-/// Returns all `(directories, files)` under the source path
+/// Returns all `(directories, files)` under the source path.
fn get_recursive_paths<P, Q>(root: P, name: Q) -> Result<(Vec<String>, Vec<String>)>
where P: AsRef<Path>, Q: AsRef<Path>
{
diff --git a/src/util.rs b/src/util.rs
index 1678973..f499b89 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,13 +1,3 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
use std::fs;
use std::path::Path;
@@ -16,7 +6,7 @@ use walkdir::WalkDir;
// Needed to set the script mode to executable.
#[cfg(unix)]
use std::os::unix::fs::OpenOptionsExt;
-// FIXME: what about Windows? Are default ACLs executable?
+// FIXME: what about Windows? Are default ACLs executable?
#[cfg(unix)]
use std::os::unix::fs::symlink as symlink_file;
@@ -25,14 +15,14 @@ use std::os::windows::fs::symlink_file;
use crate::errors::*;
-/// Convert a `&Path` to a UTF-8 `&str`
+/// Converts a `&Path` to a UTF-8 `&str`.
pub fn path_to_str(path: &Path) -> Result<&str> {
path.to_str().ok_or_else(|| {
ErrorKind::Msg(format!("path is not valid UTF-8 '{}'", path.display())).into()
})
}
-/// Wrap `fs::copy` with a nicer error message
+/// Wraps `fs::copy` with a nicer error message.
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
if fs::symlink_metadata(&from)?.file_type().is_symlink() {
let link = fs::read_link(&from)?;
@@ -45,19 +35,19 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
}
}
-/// Wrap `fs::create_dir` with a nicer error message
+/// Wraps `fs::create_dir` with a nicer error message.
pub fn create_dir<P: AsRef<Path>>(path: P) -> Result<()> {
fs::create_dir(&path)
.chain_err(|| format!("failed to create dir '{}'", path.as_ref().display()))
}
-/// Wrap `fs::create_dir_all` with a nicer error message
+/// Wraps `fs::create_dir_all` with a nicer error message.
pub fn create_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
fs::create_dir_all(&path)
.chain_err(|| format!("failed to create dir '{}'", path.as_ref().display()))
}
-/// Wrap `fs::OpenOptions::create_new().open()` as executable, with a nicer error message
+/// Wraps `fs::OpenOptions::create_new().open()` as executable, with a nicer error message.
pub fn create_new_executable<P: AsRef<Path>>(path: P) -> Result<fs::File> {
let mut options = fs::OpenOptions::new();
options.write(true).create_new(true);
@@ -66,19 +56,19 @@ pub fn create_new_executable<P: AsRef<Path>>(path: P) -> Result<fs::File> {
.chain_err(|| format!("failed to create file '{}'", path.as_ref().display()))
}
-/// Wrap `fs::OpenOptions::create_new().open()`, with a nicer error message
+/// Wraps `fs::OpenOptions::create_new().open()`, with a nicer error message.
pub fn create_new_file<P: AsRef<Path>>(path: P) -> Result<fs::File> {
fs::OpenOptions::new().write(true).create_new(true).open(&path)
.chain_err(|| format!("failed to create file '{}'", path.as_ref().display()))
}
-/// Wrap `fs::File::open()` with a nicer error message
+/// Wraps `fs::File::open()` with a nicer error message.
pub fn open_file<P: AsRef<Path>>(path: P) -> Result<fs::File> {
fs::File::open(&path)
.chain_err(|| format!("failed to open file '{}'", path.as_ref().display()))
}
-/// Wrap `remove_dir_all` with a nicer error message
+/// Wraps `remove_dir_all` with a nicer error message.
pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
crate::remove_dir_all::remove_dir_all(path.as_ref())
.chain_err(|| format!("failed to remove dir '{}'", path.as_ref().display()))
@@ -97,7 +87,7 @@ pub fn copy_recursive(src: &Path, dst: &Path) -> Result<()> {
}
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
-/// when this function is called. Invokes a callback for each path visited.
+/// when this function is called. Invokes a callback for each path visited.
pub fn copy_with_callback<F>(src: &Path, dst: &Path, mut callback: F) -> Result<()>
where F: FnMut(&Path, fs::FileType) -> Result<()>
{
@@ -118,7 +108,7 @@ pub fn copy_with_callback<F>(src: &Path, dst: &Path, mut callback: F) -> Result<
}
-/// Create an "actor" with default values and setters for all fields.
+/// Creates an "actor" with default values and setters for all fields.
macro_rules! actor {
($( #[ $attr:meta ] )+ pub struct $name:ident {
$( $( #[ $field_attr:meta ] )+ $field:ident : $type:ty = $default:expr, )*