Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
Merge pull request #102 from habitat-sh/rust-2018
Browse files Browse the repository at this point in the history
Update to rust 2018 edition
  • Loading branch information
baumanj authored Jan 9, 2019
2 parents b21f399 + b89d75f commit 22f09fc
Show file tree
Hide file tree
Showing 43 changed files with 99 additions and 129 deletions.
1 change: 1 addition & 0 deletions components/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "habitat_core"
version = "0.0.0"
edition = "2018"
authors = ["Adam Jacob <adam@chef.io>", "Jamie Winsor <reset@chef.io>", "Fletcher Nichol <fnichol@chef.io>", "Joshua Timberman <joshua@chef.io>", "Dave Parfitt <dparfitt@chef.io>", "Steven Murawski <smurawski@chef.io>"]
workspace = "../../"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/binlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use env;
use crate::env;

/// Default Binlink Dir
#[cfg(target_os = "windows")]
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use env;
use crate::env;

pub const UNSTABLE_CHANNEL: &'static str = "unstable";
pub const STABLE_CHANNEL: &'static str = "stable";
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::path::Path;
use serde::de::DeserializeOwned;
use toml;

use error::Error;
use crate::error::Error;

pub trait ConfigFile: DeserializeOwned + Sized {
type Error: StdError + From<Error>;
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/crypto/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sodiumoxide::crypto::sign;
use super::hash;
use super::keys::parse_name_with_rev;
use super::{SigKeyPair, HART_FORMAT_VERSION, SIG_HASH_TYPE};
use error::{Error, Result};
use crate::error::{Error, Result};

/// Generate and sign a package
pub fn sign<P1: ?Sized, P2: ?Sized>(src: &P1, dst: &P2, pair: &SigKeyPair) -> Result<()>
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/crypto/dpapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use winapi::shared::minwindef::DWORD;
use winapi::um::dpapi;
use winapi::um::wincrypt::CRYPTOAPI_BLOB;

use error::{Error, Result};
use crate::error::{Error, Result};

const COMPLEXITY: &'static [u8] = include_bytes!(concat!(env!("OUT_DIR"), "/hab-crypt"));

Expand Down
2 changes: 1 addition & 1 deletion components/core/src/crypto/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::ptr;
use hex;
use libsodium_sys;

use error::Result;
use crate::error::Result;

const BUF_SIZE: usize = 1024;

Expand Down
4 changes: 2 additions & 2 deletions components/core/src/crypto/keys/box_key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use super::{
get_key_revisions, mk_key_filename, mk_revision_string, parse_name_with_rev, read_key_bytes,
read_key_bytes_from_str, write_keypair_files, KeyPair, KeyType,
};
use error::{Error, Result};
use crate::error::{Error, Result};

#[derive(Debug)]
pub struct BoxSecret<'a> {
Expand Down Expand Up @@ -329,7 +329,7 @@ impl BoxKeyPair {

// Return the metadata and encrypted text from a secret payload.
// This is useful for services consuming an encrypted payload and need to decrypt it without having keys on disk
pub fn secret_metadata<'a>(payload: &'a [u8]) -> Result<BoxSecret> {
pub fn secret_metadata<'a>(payload: &'a [u8]) -> Result<BoxSecret<'_>> {
let mut lines = str::from_utf8(payload)?.lines();
let version = Self::box_key_format_version(lines.next())?;
let sender = Self::box_key_sender(lines.next())?;
Expand Down
12 changes: 6 additions & 6 deletions components/core/src/crypto/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ use base64;
use regex::Regex;
use time;

use error::{Error, Result};
use crate::error::{Error, Result};

use super::{
PUBLIC_BOX_KEY_VERSION, PUBLIC_KEY_SUFFIX, PUBLIC_SIG_KEY_VERSION, SECRET_BOX_KEY_SUFFIX,
SECRET_BOX_KEY_VERSION, SECRET_SIG_KEY_SUFFIX, SECRET_SIG_KEY_VERSION, SECRET_SYM_KEY_SUFFIX,
SECRET_SYM_KEY_VERSION,
};

lazy_static! {
lazy_static::lazy_static! {
static ref NAME_WITH_REV_RE: Regex = Regex::new(r"\A(?P<name>.+)-(?P<rev>\d{14})\z").unwrap();
static ref KEYFILE_RE: Regex =
Regex::new(r"\A(?P<name>.+)-(?P<rev>\d{14})\.(?P<suffix>[a-z]+(\.[a-z]+)?)\z").unwrap();
Expand All @@ -51,7 +51,7 @@ enum KeyType {
}

impl fmt::Display for KeyType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
KeyType::Box => write!(f, "box"),
KeyType::Sig => write!(f, "sig"),
Expand All @@ -67,7 +67,7 @@ pub enum PairType {
}

impl fmt::Display for PairType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
PairType::Public => write!(f, "public"),
PairType::Secret => write!(f, "secret"),
Expand Down Expand Up @@ -571,7 +571,7 @@ fn write_keypair_files(

#[cfg(not(windows))]
fn set_permissions<T: AsRef<Path>>(path: T) -> Result<()> {
use util::posix_perm;
use crate::util::posix_perm;

use super::KEY_PERMISSIONS;

Expand All @@ -580,7 +580,7 @@ fn set_permissions<T: AsRef<Path>>(path: T) -> Result<()> {

#[cfg(windows)]
fn set_permissions<T: AsRef<Path>>(path: T) -> Result<()> {
use util::win_perm;
use crate::util::win_perm;

win_perm::harden_path(path.as_ref())
}
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/crypto/keys/sig_key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use super::{
get_key_revisions, mk_key_filename, mk_revision_string, parse_name_with_rev, read_key_bytes,
write_keypair_files, KeyPair, KeyType, PairType, TmpKeyfile,
};
use error::{Error, Result};
use crate::error::{Error, Result};

pub type SigKeyPair = KeyPair<SigPublicKey, SigSecretKey>;

Expand Down
4 changes: 2 additions & 2 deletions components/core/src/crypto/keys/sym_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ use super::{
get_key_revisions, mk_key_filename, mk_revision_string, parse_name_with_rev, read_key_bytes,
write_keypair_files, KeyPair, KeyType, PairType, TmpKeyfile,
};
use error::{Error, Result};
use crate::error::{Error, Result};

pub type SymKey = KeyPair<(), SymSecretKey>;

impl fmt::Debug for SymKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SymKey")
}
}
Expand Down
8 changes: 4 additions & 4 deletions components/core/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@
//! <symkey_base64>
//! ```

use rust_crypto;
use crate::rust_crypto;
use std::path::{Path, PathBuf};

use env as henv;
use crate::env as henv;
pub use sodiumoxide::init;

pub use self::keys::box_key_pair::BoxKeyPair;
pub use self::keys::sig_key_pair::SigKeyPair;
pub use self::keys::sym_key::SymKey;
use fs::cache_key_path;
use crate::fs::cache_key_path;

/// The suffix on the end of a public sig/box file
pub static PUBLIC_KEY_SUFFIX: &'static str = "pub";
Expand Down Expand Up @@ -295,7 +295,7 @@ pub mod test_support {

use time;

use error as herror;
use crate::error as herror;

pub fn fixture(name: &str) -> PathBuf {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
Expand Down
4 changes: 2 additions & 2 deletions components/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use libarchive;
use regex;
use toml;

use package::{self, Identifiable};
use crate::package::{self, Identifiable};

pub type Result<T> = result::Result<T, Error>;

Expand Down Expand Up @@ -169,7 +169,7 @@ pub enum Error {
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let msg = match *self {
Error::ArchiveError(ref err) => format!("{}", err),
Error::BadBindingMode(ref value) => format!("Unknown binding mode '{}'", value),
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl fmt::Display for Event {
// tool with a `"line exceeded maximum length"` error. This ignore should be removed when we
// upgrade rustfmt and retry.
#[cfg_attr(rustfmt, rustfmt_skip)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let msg = match *self {
Event::ProjectCreate { origin: _, package: _, account: _ } => "project-create",
Event::PackageUpload { origin: _, package: _, version: _, release: _, target: _,
Expand Down
10 changes: 5 additions & 5 deletions components/core/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::str::FromStr;

use users;
use crate::users;

use env as henv;
use error::Result;
use package::{Identifiable, PackageIdent, PackageInstall};
use crate::env as henv;
use crate::error::Result;
use crate::package::{Identifiable, PackageIdent, PackageInstall};

/// The default root path of the Habitat filesystem
pub const ROOT_PATH: &'static str = "hab";
Expand Down Expand Up @@ -54,7 +54,7 @@ pub const SYSTEMDRIVE_ENVVAR: &'static str = "SYSTEMDRIVE";
/// The file where user-defined configuration for each service is found.
pub const USER_CONFIG_FILE: &'static str = "user.toml";

lazy_static! {
lazy_static::lazy_static! {
/// The default filesystem root path.
///
/// WARNING: On Windows this variable mutates on first call if an environment variable with
Expand Down
38 changes: 5 additions & 33 deletions components/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,15 @@
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]

extern crate ansi_term;
extern crate base64;
extern crate crypto as rust_crypto;
#[cfg(windows)]
extern crate ctrlc;
extern crate dirs;
extern crate errno;
extern crate hex;
#[cfg(test)]
extern crate hyper;
#[macro_use]
extern crate lazy_static;
extern crate libarchive;
extern crate libc;
extern crate libsodium_sys;

#[macro_use]
extern crate log;
extern crate rand;
extern crate regex;
extern crate serde;
extern crate tempfile;
#[macro_use]
extern crate serde_derive;

// This is a little gross, but we only need the macros in tests right
// now.
#[cfg(test)]
#[macro_use]
extern crate serde_json;
#[cfg(not(test))]
extern crate serde_json;

extern crate sodiumoxide;
extern crate time;
extern crate toml;
extern crate typemap;
extern crate url as extern_url;
extern crate serde_derive;

#[cfg(not(windows))]
extern crate users as linux_users;
Expand Down Expand Up @@ -84,12 +56,12 @@ pub mod util;

use std::path::PathBuf;

pub use os::filesystem;
pub use os::users;
pub use crate::os::filesystem;
pub use crate::os::users;

pub const AUTH_TOKEN_ENVVAR: &'static str = "HAB_AUTH_TOKEN";

lazy_static! {
lazy_static::lazy_static! {
pub static ref PROGRAM_NAME: String = {
let arg0 = std::env::args().next().map(|p| PathBuf::from(p));
arg0.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/os/process/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::process::Command;
use libc::{self, pid_t};

use super::{OsSignal, Signal};
use error::{Error, Result};
use crate::error::{Error, Result};

pub type Pid = libc::pid_t;
pub type SignalCode = libc::c_int;
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/os/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use self::imp::*;

pub trait OsSignal {
fn os_signal(&self) -> SignalCode;
fn from_signal_code(SignalCode) -> Option<Signal>;
fn from_signal_code(_: SignalCode) -> Option<Signal>;
}

#[allow(non_snake_case)]
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/os/process/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use winapi::um::processthreadsapi;
use winapi::um::winnt::{HANDLE, PROCESS_QUERY_LIMITED_INFORMATION, PROCESS_TERMINATE};

use super::{OsSignal, Signal};
use error::{Error, Result};
use crate::error::{Error, Result};

const STILL_ACTIVE: u32 = 259;

Expand Down
4 changes: 2 additions & 2 deletions components/core/src/os/process/windows_child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ use winapi::um::winnt::{
READ_CONTROL, WRITE_DAC,
};

use error::{Error, Result};
use crate::error::{Error, Result};
use habitat_win_users::sid::{self, Sid};

use super::super::super::crypto::dpapi::decrypt;
use super::super::users::get_current_username;

lazy_static! {
lazy_static::lazy_static! {
static ref CREATE_PROCESS_LOCK: Mutex<()> = Mutex::new(());
}

Expand Down
2 changes: 1 addition & 1 deletion components/core/src/os/signals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// our homespun implementation. Check for status of that here:
// https://github.com/rust-lang/rfcs/issues/1368

use os::process;
use crate::os::process;

#[allow(dead_code)]
pub enum SignalEvent {
Expand Down
4 changes: 2 additions & 2 deletions components/core/src/os/signals/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
use std::collections::VecDeque;
use std::sync::{Mutex, Once, ONCE_INIT};

use os::process::{OsSignal, Signal, SignalCode};
use crate::os::process::{OsSignal, Signal, SignalCode};

use super::SignalEvent;

static INIT: Once = ONCE_INIT;

lazy_static! {
lazy_static::lazy_static! {
static ref CAUGHT_SIGNALS: Mutex<VecDeque<SignalCode>> = Mutex::new(VecDeque::new());
}

Expand Down
4 changes: 2 additions & 2 deletions components/core/src/os/system/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use std::mem;

use libc;

use crate::error::{Error, Result};
use crate::os::system::Uname;
use errno::errno;
use error::{Error, Result};
use os::system::Uname;

pub fn uname() -> Result<Uname> {
unsafe { uname_libc() }
Expand Down
4 changes: 2 additions & 2 deletions components/core/src/os/system/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use error::Result;
use os::system::Uname;
use crate::error::Result;
use crate::os::system::Uname;

pub fn uname() -> Result<Uname> {
Ok(Uname {
Expand Down
Loading

0 comments on commit 22f09fc

Please sign in to comment.