diff --git a/components/builder-jobsrv/src/server.rs b/components/builder-jobsrv/src/server.rs index 2c3d786a3b..2eac6a76e2 100644 --- a/components/builder-jobsrv/src/server.rs +++ b/components/builder-jobsrv/src/server.rs @@ -11,7 +11,8 @@ use std::thread::{self, JoinHandle}; use dbcache::{self, InstaSet}; use linked_hash_map::LinkedHashMap; -use hab_net::server::{Application, Envelope, NetIdent, RouteConn, Service, Supervisor, Supervisable, ToAddrString}; +use hab_net::server::{Application, Envelope, NetIdent, RouteConn, Service, Supervisor, + Supervisable, ToAddrString}; use protobuf::{parse_from_bytes, Message}; use protocol::net::{self, ErrCode}; use protocol::jobsrv; @@ -256,7 +257,9 @@ impl WorkerManager { }) } - pub fn start(ctx: Arc>, config: Arc>) -> Result> { + pub fn start(ctx: Arc>, + config: Arc>) + -> Result> { let (tx, rx) = mpsc::sync_channel(1); let handle = thread::Builder::new() .name("worker-manager".to_string()) @@ -289,8 +292,9 @@ impl WorkerManager { loop { { let timeout = self.poll_timeout(); - let mut items = - [self.hb_sock.as_poll_item(1), self.rq_sock.as_poll_item(1), self.work_mgr_sock.as_poll_item(1)]; + let mut items = [self.hb_sock.as_poll_item(1), + self.rq_sock.as_poll_item(1), + self.work_mgr_sock.as_poll_item(1)]; // Poll until timeout or message is received. Checking for the zmq::POLLIN flag on // a poll item's revents will let you know if you have received a message or not // on that socket. diff --git a/components/common/src/error.rs b/components/common/src/error.rs index a048120276..007dd261bd 100644 --- a/components/common/src/error.rs +++ b/components/common/src/error.rs @@ -39,7 +39,9 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let msg = match *self { - Error::CantUploadGossipToml => format!("Can't upload gossip.toml, it's a reserved file name"), + Error::CantUploadGossipToml => { + format!("Can't upload gossip.toml, it's a reserved file name") + } Error::CryptoKeyError(ref s) => format!("Missing or invalid key: {}", s), Error::GossipFileRelativePath(ref s) => { format!("Path for gossip file cannot have relative components (eg: ..): {}", @@ -65,7 +67,9 @@ impl error::Error for Error { match *self { Error::CantUploadGossipToml => "Can't upload gossip.toml, it's a reserved filename", Error::CryptoKeyError(_) => "Missing or invalid key", - Error::GossipFileRelativePath(_) => "Path for gossip file cannot have relative components (eg: ..)", + Error::GossipFileRelativePath(_) => { + "Path for gossip file cannot have relative components (eg: ..)" + } Error::DepotClient(ref err) => err.description(), Error::FileNameError => "Failed to extract a filename from a path", Error::HabitatCore(ref err) => err.description(), diff --git a/components/common/src/gossip_file.rs b/components/common/src/gossip_file.rs index 2d8972930a..0964152f25 100644 --- a/components/common/src/gossip_file.rs +++ b/components/common/src/gossip_file.rs @@ -52,7 +52,7 @@ impl GossipFile { let pstr = format!("{}", part.as_os_str().to_string_lossy().into_owned()); if &pstr == ".." { return Err(Error::GossipFileRelativePath(path.to_string_lossy() - .into_owned())); + .into_owned())); } } let mut f = try!(File::open(&path)); @@ -93,7 +93,7 @@ impl GossipFile { let pstr = format!("{}", part.as_os_str().to_string_lossy().into_owned()); if &pstr == ".." { return Err(Error::GossipFileRelativePath(path.to_string_lossy() - .into_owned())); + .into_owned())); } } let mut f = try!(File::open(&path)); @@ -482,7 +482,7 @@ mod test { let cf = GossipFile::from_file(ServiceGroup::from_str("petty.gunslingers").unwrap(), fixture("foo.toml").as_path(), 2) - .unwrap(); + .unwrap(); assert_eq!(cf.service_group, ServiceGroup::from_str("petty.gunslingers").unwrap()); assert_eq!(cf.file_name, GOSSIP_TOML); @@ -505,15 +505,14 @@ mod test { fn new_from_file_encrypt() { let cache = TempDir::new("key_cache").unwrap(); let user_pair = BoxKeyPair::generate_pair_for_user("testuser", cache.path()).unwrap(); - let service_pair = BoxKeyPair::generate_pair_for_service("someorg", - "petty.gunslingers", - cache.path()) - .unwrap(); + let service_pair = + BoxKeyPair::generate_pair_for_service("someorg", "petty.gunslingers", cache.path()) + .unwrap(); let gf = GossipFile::from_file_encrypt(&user_pair, &service_pair, fixture("foo.toml").as_path(), 1) - .unwrap(); + .unwrap(); assert_eq!(gf.service_group, ServiceGroup::from_str("petty.gunslingers@someorg").unwrap()); // keeps it's filename @@ -538,7 +537,7 @@ mod test { let cf = GossipFile::from_body(ServiceGroup::from_str("chromeo.footwork").unwrap(), "Rage=1\n".as_bytes().to_vec(), 45) - .unwrap(); + .unwrap(); assert_eq!(cf.service_group, ServiceGroup::from_str("chromeo.footwork").unwrap()); assert_eq!(cf.file_name, GOSSIP_TOML); @@ -565,12 +564,12 @@ mod test { .unwrap(), "rope=1\n".as_bytes().to_vec(), 20) - .unwrap(); + .unwrap(); let other = GossipFile::from_body(ServiceGroup::from_str("foofighters.arlandria").unwrap(), "rope=1\n".as_bytes().to_vec(), 99) - .unwrap(); + .unwrap(); assert_eq!(me == other, false); assert_eq!(me.update_via(other.clone()), true); assert_eq!(me == other, true); @@ -581,20 +580,20 @@ mod test { let mut me = GossipFile::from_body(ServiceGroup::from_str("heart.barracuda").unwrap(), "woot=1\n".as_bytes().to_vec(), 99) - .unwrap(); + .unwrap(); let other_service = GossipFile::from_body(ServiceGroup::from_str("oops.barracuda") .unwrap(), "woot=1\n".as_bytes().to_vec(), 20) - .unwrap(); + .unwrap(); assert_eq!(me.update_via(other_service.clone()), false); assert_eq!(me == other_service, false); let other_group = GossipFile::from_body(ServiceGroup::from_str("heart.oops").unwrap(), "woot=1\n".as_bytes().to_vec(), 20) - .unwrap(); + .unwrap(); assert_eq!(me.update_via(other_group.clone()), false); assert_eq!(me == other_group, false); @@ -602,14 +601,14 @@ mod test { .unwrap(), "woot=1\n".as_bytes().to_vec(), 20) - .unwrap(); + .unwrap(); assert_eq!(me.update_via(other_file_name.clone()), false); assert_eq!(me == other_file_name, false); let other_body = GossipFile::from_body(ServiceGroup::from_str("heart.barracuda").unwrap(), "oops=1".as_bytes().to_vec(), 20) - .unwrap(); + .unwrap(); assert_eq!(me.update_via(other_body.clone()), false); assert_eq!(me == other_body, false); } @@ -620,11 +619,11 @@ mod test { .unwrap(), "tracks=1\n".as_bytes().to_vec(), 42) - .unwrap(); + .unwrap(); let mut me = GossipFile::from_body(ServiceGroup::from_str("heart.barracuda").unwrap(), "tracks=1\n".as_bytes().to_vec(), 42) - .unwrap(); + .unwrap(); assert_eq!(me.update_via(other.clone()), false); assert_eq!(me == other, false); } @@ -634,11 +633,11 @@ mod test { let other = GossipFile::from_body(ServiceGroup::from_str("heart.barracuda").unwrap(), "woot=1\n".as_bytes().to_vec(), 20) - .unwrap(); + .unwrap(); let mut me = GossipFile::from_body(ServiceGroup::from_str("heart.barracuda").unwrap(), "woot=1\n".as_bytes().to_vec(), 20) - .unwrap(); + .unwrap(); assert_eq!(me.update_via(other.clone()), false); assert_eq!(me == other, true); } diff --git a/components/common/src/wire_message.rs b/components/common/src/wire_message.rs index 077b23f570..e4d14f06dc 100644 --- a/components/common/src/wire_message.rs +++ b/components/common/src/wire_message.rs @@ -202,14 +202,14 @@ impl WireMessage { Some(k) => k, None => { return Err(Error::WireDecode("Key not present for encrypted message" - .to_string())) + .to_string())) } }; let nonce = match self.nonce.as_ref() { Some(n) => n, None => { return Err(Error::WireDecode("Nonce not present for encrypted message" - .to_string())) + .to_string())) } }; let sym_key = match sym_key.as_ref() { diff --git a/components/core/src/crypto/artifact.rs b/components/core/src/crypto/artifact.rs index 4c47ee1c08..98cc490d3c 100644 --- a/components/core/src/crypto/artifact.rs +++ b/components/core/src/crypto/artifact.rs @@ -81,7 +81,7 @@ pub fn verify(src: &P1, cache_key_path: &P2) -> Result<( match reader.read_line(&mut buffer) { Ok(0) => { return Err(Error::CryptoError("Corrupt payload, can't read format version" - .to_string())) + .to_string())) } Ok(_) => { if buffer.trim() != HART_FORMAT_VERSION { @@ -98,7 +98,7 @@ pub fn verify(src: &P1, cache_key_path: &P2) -> Result<( let mut buffer = String::new(); if try!(reader.read_line(&mut buffer)) <= 0 { return Err(Error::CryptoError("Corrupt payload, can't read origin key name" - .to_string())); + .to_string())); } try!(SigKeyPair::get_pair_for(buffer.trim(), cache_key_path)) }; @@ -177,7 +177,7 @@ pub fn artifact_signer>(src: &P) -> Result { match reader.read_line(&mut buffer) { Ok(0) => { return Err(Error::CryptoError("Corrupt payload, can't read format version" - .to_string())) + .to_string())) } Ok(_) => { if buffer.trim() != HART_FORMAT_VERSION { @@ -194,7 +194,7 @@ pub fn artifact_signer>(src: &P) -> Result { let mut buffer = String::new(); if try!(reader.read_line(&mut buffer)) <= 0 { return Err(Error::CryptoError("Corrupt payload, can't read origin key name" - .to_string())); + .to_string())); } try!(parse_name_with_rev(buffer.trim())); buffer.trim().to_string() @@ -233,7 +233,7 @@ mod test { // Delete the secret key fs::remove_file(SigKeyPair::get_secret_key_path(&pair.name_with_rev(), cache.path()) - .unwrap()) + .unwrap()) .unwrap(); // Now reload the key pair which will be missing the secret key let pair = SigKeyPair::get_latest_pair_for("unicorn", cache.path()).unwrap(); @@ -251,7 +251,7 @@ mod test { // Delete the public key fs::remove_file(SigKeyPair::get_public_key_path(&pair.name_with_rev(), cache.path()) - .unwrap()) + .unwrap()) .unwrap(); // Now reload the key pair which will be missing the public key let _ = SigKeyPair::get_latest_pair_for("unicorn", cache.path()).unwrap(); @@ -347,9 +347,9 @@ mod test { let dst = cache.path().join("signed.dat"); let mut f = File::create(&dst).unwrap(); f.write_all(format!("HART-1\n{}\nBLAKE2b\nnot:base64:signature", - pair.name_with_rev()) - .as_bytes()) - .unwrap(); + pair.name_with_rev()) + .as_bytes()) + .unwrap(); verify(&dst, cache.path()).unwrap(); } @@ -362,7 +362,7 @@ mod test { let dst = cache.path().join("signed.dat"); let mut f = File::create(&dst).unwrap(); f.write_all(format!("HART-1\n{}\nBLAKE2b\nbase64\n", pair.name_with_rev()).as_bytes()) - .unwrap(); + .unwrap(); verify(&dst, cache.path()).unwrap(); } diff --git a/components/core/src/crypto/hash.rs b/components/core/src/crypto/hash.rs index e6a95636dc..d07e8428e0 100644 --- a/components/core/src/crypto/hash.rs +++ b/components/core/src/crypto/hash.rs @@ -86,18 +86,18 @@ mod test { #[allow(dead_code)] fn mk_local_tmpdir() -> PathBuf { let dir = env::current_exe() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .join("tmp"); + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .join("tmp"); fs::create_dir_all(&dir).unwrap(); dir } @@ -137,9 +137,9 @@ mod test { _ => Client::new(), }; let mut response = client.get(url) - .header(header::Connection::close()) - .send() - .unwrap(); + .header(header::Connection::close()) + .send() + .unwrap(); let mut f = File::create(&file).unwrap(); io::copy(&mut response, &mut f).unwrap(); } diff --git a/components/core/src/crypto/keys/box_key_pair.rs b/components/core/src/crypto/keys/box_key_pair.rs index b32a4666e1..ac7a6ee7ed 100644 --- a/components/core/src/crypto/keys/box_key_pair.rs +++ b/components/core/src/crypto/keys/box_key_pair.rs @@ -161,21 +161,21 @@ impl BoxKeyPair { } None => { return Err(Error::CryptoError("Corrupt payload, can't read file version" - .to_string())); + .to_string())); } }; let sender = match lines.next() { Some(val) => try!(Self::get_pair_for(&val, cache_key_path)), None => { return Err(Error::CryptoError("Corrupt payload, can't read sender key name" - .to_string())); + .to_string())); } }; let receiver = match lines.next() { Some(val) => try!(Self::get_pair_for(&val, cache_key_path)), None => { return Err(Error::CryptoError("Corrupt payload, can't read receiver key name" - .to_string())); + .to_string())); } }; let nonce = match lines.next() { @@ -204,7 +204,7 @@ impl BoxKeyPair { } None => { return Err(Error::CryptoError("Corrupt payload, can't read ciphertext" - .to_string())); + .to_string())); } }; @@ -216,7 +216,7 @@ impl BoxKeyPair { Err(_) => { return Err(Error::CryptoError("Secret key, public key, and nonce could not \ decrypt ciphertext" - .to_string())) + .to_string())) } } } @@ -312,7 +312,7 @@ mod test { fn generated_service_pair() { let cache = TempDir::new("key_cache").unwrap(); let pair = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); assert_eq!(pair.name, "tnt.default@acme"); match pair.public() { @@ -355,12 +355,11 @@ mod test { let pairs = BoxKeyPair::get_pairs_for("wecoyote", cache.path()).unwrap(); assert_eq!(pairs.len(), 1); - let _ = match wait_until_ok(|| { - BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()) - }) { - Some(pair) => pair, - None => panic!("Failed to generate another keypair after waiting"), - }; + let _ = + match wait_until_ok(|| BoxKeyPair::generate_pair_for_user("wecoyote", cache.path())) { + Some(pair) => pair, + None => panic!("Failed to generate another keypair after waiting"), + }; let pairs = BoxKeyPair::get_pairs_for("wecoyote", cache.path()).unwrap(); assert_eq!(pairs.len(), 2); @@ -374,12 +373,11 @@ mod test { fn get_pair_for() { let cache = TempDir::new("key_cache").unwrap(); let p1 = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); - let p2 = match wait_until_ok(|| { - BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()) - }) { - Some(pair) => pair, - None => panic!("Failed to generate another keypair after waiting"), - }; + let p2 = + match wait_until_ok(|| BoxKeyPair::generate_pair_for_user("wecoyote", cache.path())) { + Some(pair) => pair, + None => panic!("Failed to generate another keypair after waiting"), + }; let p1_fetched = BoxKeyPair::get_pair_for(&p1.name_with_rev(), cache.path()).unwrap(); assert_eq!(p1.name, p1_fetched.name); @@ -410,12 +408,11 @@ mod test { fn get_latest_pair_for_multiple() { let cache = TempDir::new("key_cache").unwrap(); let _ = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); - let p2 = match wait_until_ok(|| { - BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()) - }) { - Some(pair) => pair, - None => panic!("Failed to generate another keypair after waiting"), - }; + let p2 = + match wait_until_ok(|| BoxKeyPair::generate_pair_for_user("wecoyote", cache.path())) { + Some(pair) => pair, + None => panic!("Failed to generate another keypair after waiting"), + }; let latest = BoxKeyPair::get_latest_pair_for("wecoyote", cache.path()).unwrap(); assert_eq!(latest.name, p2.name); @@ -469,7 +466,7 @@ mod test { fn encrypt_and_decrypt_from_user_to_service() { let cache = TempDir::new("key_cache").unwrap(); let service = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); let user = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let ciphertext = user.encrypt("I wish to buy more rockets".as_bytes(), &service).unwrap(); @@ -481,7 +478,7 @@ mod test { fn encrypt_and_decrypt_from_service_to_user() { let cache = TempDir::new("key_cache").unwrap(); let service = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); let user = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let ciphertext = service.encrypt("Out of rockets".as_bytes(), &user).unwrap(); @@ -499,18 +496,17 @@ mod test { // required on each end { let sender = BoxKeyPair::generate_pair_for_user("wecoyote", full_cache.path()).unwrap(); - let receiver = BoxKeyPair::generate_pair_for_service("acme", - "tnt.default", - full_cache.path()) - .unwrap(); + let receiver = + BoxKeyPair::generate_pair_for_service("acme", "tnt.default", full_cache.path()) + .unwrap(); // Prepare the sender cache with sender's secret and receiver's public keys let secret = BoxKeyPair::get_secret_key_path(&sender.name_with_rev(), full_cache.path()) - .unwrap(); + .unwrap(); let public = BoxKeyPair::get_public_key_path(&receiver.name_with_rev(), full_cache.path()) - .unwrap(); + .unwrap(); fs::copy(&secret, sender_cache.path().join(&secret.file_name().unwrap())) .unwrap(); @@ -521,10 +517,10 @@ mod test { // Prepare the receiver cache with receivers's secret and sender's public keys let secret = BoxKeyPair::get_secret_key_path(&receiver.name_with_rev(), full_cache.path()) - .unwrap(); + .unwrap(); let public = BoxKeyPair::get_public_key_path(&sender.name_with_rev(), full_cache.path()) - .unwrap(); + .unwrap(); fs::copy(&secret, receiver_cache.path().join(&secret.file_name().unwrap())) .unwrap(); @@ -538,7 +534,7 @@ mod test { // Load the sender and receiver keys from sender cache to encrypt let sender = BoxKeyPair::get_latest_pair_for("wecoyote", sender_cache.path()).unwrap(); let receiver = BoxKeyPair::get_latest_pair_for("tnt.default@acme", sender_cache.path()) - .unwrap(); + .unwrap(); sender.encrypt("Falling hurts".as_bytes(), &receiver).unwrap() }; @@ -555,11 +551,11 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); let sender = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let receiver = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); // Delete the sender's secret key fs::remove_file(BoxKeyPair::get_secret_key_path(&sender.name_with_rev(), cache.path()) - .unwrap()) + .unwrap()) .unwrap(); // Now reload the sender's pair which will be missing the secret key let sender = BoxKeyPair::get_latest_pair_for("wecoyote", cache.path()).unwrap(); @@ -573,11 +569,11 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); let sender = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let receiver = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); // Delete the receiver's public key fs::remove_file(BoxKeyPair::get_public_key_path(&receiver.name_with_rev(), cache.path()) - .unwrap()) + .unwrap()) .unwrap(); // Now reload the receiver's pair which will be missing the public key let receiver = BoxKeyPair::get_latest_pair_for("tnt.default@acme", cache.path()).unwrap(); @@ -591,11 +587,11 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); let sender = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let receiver = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); // Delete the receiver's secret key fs::remove_file(BoxKeyPair::get_secret_key_path(&receiver.name_with_rev(), cache.path()) - .unwrap()) + .unwrap()) .unwrap(); let ciphertext = sender.encrypt("problems ahead".as_bytes(), &receiver).unwrap(); @@ -608,11 +604,11 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); let sender = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let receiver = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); // Delete the sender's public key fs::remove_file(BoxKeyPair::get_public_key_path(&sender.name_with_rev(), cache.path()) - .unwrap()) + .unwrap()) .unwrap(); let ciphertext = sender.encrypt("problems ahead".as_bytes(), &receiver).unwrap(); @@ -659,7 +655,7 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); let sender = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let receiver = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); let payload = format!("BOX-1\n{}\n{}\nnot:base64", sender.name_with_rev(), @@ -673,7 +669,7 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); let sender = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let receiver = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); let payload = format!("BOX-1\n{}\n{}\nuhoh", sender.name_with_rev(), @@ -687,7 +683,7 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); let sender = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let receiver = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); let payload = sender.encrypt("problems ahead".as_bytes(), &receiver).unwrap(); let mut botched = String::new(); @@ -711,7 +707,7 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); let sender = BoxKeyPair::generate_pair_for_user("wecoyote", cache.path()).unwrap(); let receiver = BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) - .unwrap(); + .unwrap(); let payload = sender.encrypt("problems ahead".as_bytes(), &receiver).unwrap(); let mut botched = String::new(); diff --git a/components/core/src/crypto/keys/mod.rs b/components/core/src/crypto/keys/mod.rs index 969c542652..31ef9edda2 100644 --- a/components/core/src/crypto/keys/mod.rs +++ b/components/core/src/crypto/keys/mod.rs @@ -344,7 +344,8 @@ fn write_keypair_files(key_type: KeyType, return Err(Error::BadKeyPath(public_keyfile.to_string_lossy().into_owned())); } if public_keyfile.exists() { - return Err(Error::CryptoError(format!("Public keyfile or a directory already exists {}", + return Err(Error::CryptoError(format!("Public keyfile or a directory already \ + exists {}", public_keyfile.display()))); } let public_file = try!(File::create(public_keyfile)); @@ -372,7 +373,8 @@ fn write_keypair_files(key_type: KeyType, return Err(Error::BadKeyPath(secret_keyfile.to_string_lossy().into_owned())); } if secret_keyfile.exists() { - return Err(Error::CryptoError(format!("Secret keyfile or a directory already exists {}", + return Err(Error::CryptoError(format!("Secret keyfile or a directory already \ + exists {}", secret_keyfile.display()))); } let secret_file = try!(File::create(secret_keyfile)); @@ -491,7 +493,7 @@ mod test { super::read_key_bytes(keyfile.as_path()).unwrap(); } - + #[test] fn get_user_key_revisions() { let cache = TempDir::new("key_cache").unwrap(); @@ -514,10 +516,13 @@ mod test { let cache = TempDir::new("key_cache").unwrap(); for _ in 0..3 { - wait_until_ok(|| BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path())); + wait_until_ok(|| { + BoxKeyPair::generate_pair_for_service("acme", "tnt.default", cache.path()) + }); } - let _ = BoxKeyPair::generate_pair_for_service("acyou", "tnt.default", cache.path()).unwrap(); + let _ = BoxKeyPair::generate_pair_for_service("acyou", "tnt.default", cache.path()) + .unwrap(); let revisions = super::get_key_revisions("tnt.default@acme", cache.path()).unwrap(); assert_eq!(3, revisions.len()); diff --git a/components/core/src/crypto/keys/sig_key_pair.rs b/components/core/src/crypto/keys/sig_key_pair.rs index 6c9077a852..8ad0dac847 100644 --- a/components/core/src/crypto/keys/sig_key_pair.rs +++ b/components/core/src/crypto/keys/sig_key_pair.rs @@ -305,7 +305,8 @@ impl SigKeyPair { return Err(Error::CryptoError(msg)); } else { // Otherwise, hashes match and we can skip writing over the exisiting file - debug!("New content hash matches existing file {} hash, removing temp key file {}.", + debug!("New content hash matches existing file {} hash, removing temp key file \ + {}.", keyfile.display(), tmpfile.path.display()); try!(fs::remove_file(&tmpfile.path)); @@ -407,12 +408,11 @@ mod test { let pairs = SigKeyPair::get_pairs_for("unicorn", cache.path()).unwrap(); assert_eq!(pairs.len(), 1); - let _ = match wait_until_ok(|| { - SigKeyPair::generate_pair_for_origin("unicorn", cache.path()) - }) { - Some(pair) => pair, - None => panic!("Failed to generate another keypair after waiting"), - }; + let _ = + match wait_until_ok(|| SigKeyPair::generate_pair_for_origin("unicorn", cache.path())) { + Some(pair) => pair, + None => panic!("Failed to generate another keypair after waiting"), + }; let pairs = SigKeyPair::get_pairs_for("unicorn", cache.path()).unwrap(); assert_eq!(pairs.len(), 2); @@ -426,12 +426,11 @@ mod test { fn get_pair_for() { let cache = TempDir::new("key_cache").unwrap(); let p1 = SigKeyPair::generate_pair_for_origin("unicorn", cache.path()).unwrap(); - let p2 = match wait_until_ok(|| { - SigKeyPair::generate_pair_for_origin("unicorn", cache.path()) - }) { - Some(pair) => pair, - None => panic!("Failed to generate another keypair after waiting"), - }; + let p2 = + match wait_until_ok(|| SigKeyPair::generate_pair_for_origin("unicorn", cache.path())) { + Some(pair) => pair, + None => panic!("Failed to generate another keypair after waiting"), + }; let p1_fetched = SigKeyPair::get_pair_for(&p1.name_with_rev(), cache.path()).unwrap(); assert_eq!(p1.name, p1_fetched.name); @@ -462,12 +461,11 @@ mod test { fn get_latest_pair_for_multiple() { let cache = TempDir::new("key_cache").unwrap(); let _ = SigKeyPair::generate_pair_for_origin("unicorn", cache.path()).unwrap(); - let p2 = match wait_until_ok(|| { - SigKeyPair::generate_pair_for_origin("unicorn", cache.path()) - }) { - Some(pair) => pair, - None => panic!("Failed to generate another keypair after waiting"), - }; + let p2 = + match wait_until_ok(|| SigKeyPair::generate_pair_for_origin("unicorn", cache.path())) { + Some(pair) => pair, + None => panic!("Failed to generate another keypair after waiting"), + }; let latest = SigKeyPair::get_latest_pair_for("unicorn", cache.path()).unwrap(); assert_eq!(latest.name, p2.name); diff --git a/components/core/src/crypto/keys/sym_key.rs b/components/core/src/crypto/keys/sym_key.rs index 694b9bb848..257d9680b1 100644 --- a/components/core/src/crypto/keys/sym_key.rs +++ b/components/core/src/crypto/keys/sym_key.rs @@ -212,7 +212,7 @@ impl SymKey { Ok(msg) => Ok(msg), Err(_) => { Err(Error::CryptoError("Secret key and nonce could not decrypt ciphertext" - .to_string())) + .to_string())) } } } @@ -338,7 +338,8 @@ impl SymKey { return Err(Error::CryptoError(msg)); } else { // Otherwise, hashes match and we can skip writing over the exisiting file - debug!("New content hash matches existing file {} hash, removing temp key file {}.", + debug!("New content hash matches existing file {} hash, removing temp key file \ + {}.", secret_keyfile.display(), tmpfile.path.display()); try!(fs::remove_file(&tmpfile.path)); diff --git a/components/core/src/crypto/mod.rs b/components/core/src/crypto/mod.rs index ad6df34f2e..c8301a4536 100644 --- a/components/core/src/crypto/mod.rs +++ b/components/core/src/crypto/mod.rs @@ -289,16 +289,16 @@ pub mod test_support { pub fn fixture(name: &str) -> PathBuf { let file = env::current_exe() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .join("tests") - .join("fixtures") - .join(name); + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .join("tests") + .join("fixtures") + .join(name); if !file.is_file() { panic!("No fixture {} exists!", file.display()); } diff --git a/components/core/src/error.rs b/components/core/src/error.rs index b6c56df05f..f2d4369645 100644 --- a/components/core/src/error.rs +++ b/components/core/src/error.rs @@ -97,7 +97,8 @@ impl fmt::Display for Error { f) } Error::ConfigInvalidSocketAddrV4(ref f) => { - format!("Invalid Ipv4 network address pair in config, field={}. (example: \"127.0.0.0:8080\")", + format!("Invalid Ipv4 network address pair in config, field={}. (example: \ + \"127.0.0.0:8080\")", f) } Error::ConfigInvalidString(ref f) => { @@ -148,15 +149,27 @@ impl error::Error for Error { Error::BadKeyPath(_) => "An absolute path to a file on disk is required", Error::ConfigFileIO(_) => "Unable to read the raw contents of a configuration file", Error::ConfigFileSyntax(_) => "Error parsing contents of configuration file", - Error::ConfigInvalidArray(_) => "Invalid array of values encountered while parsing a configuration file", - Error::ConfigInvalidIpv4Addr(_) => "Invalid Ipv4 network address encountered while parsing a configuration file", - Error::ConfigInvalidSocketAddrV4(_) => "Invalid Ipv4 network address pair encountered while parsing a configuration file", - Error::ConfigInvalidString(_) => "Invalid string value encountered while parsing a configuration file", + Error::ConfigInvalidArray(_) => { + "Invalid array of values encountered while parsing a configuration file" + } + Error::ConfigInvalidIpv4Addr(_) => { + "Invalid Ipv4 network address encountered while parsing a configuration file" + } + Error::ConfigInvalidSocketAddrV4(_) => { + "Invalid Ipv4 network address pair encountered while parsing a configuration file" + } + Error::ConfigInvalidString(_) => { + "Invalid string value encountered while parsing a configuration file" + } Error::CryptoError(_) => "Crypto error", Error::FileNotFound(_) => "File not found", - Error::InvalidPackageIdent(_) => "Package identifiers must be in origin/name format (example: acme/redis)", + Error::InvalidPackageIdent(_) => { + "Package identifiers must be in origin/name format (example: acme/redis)" + } Error::InvalidProxyValue(_) => "Invalid proxy value", - Error::InvalidServiceGroup(_) => "Service group strings must be in service.group format (example: redis.production)", + Error::InvalidServiceGroup(_) => { + "Service group strings must be in service.group format (example: redis.production)" + } Error::IO(ref err) => err.description(), Error::MetaFileMalformed(_) => "MetaFile didn't contain a valid UTF-8 string", Error::MetaFileNotFound(_) => "Failed to read an archive's metafile", diff --git a/components/core/src/package/ident.rs b/components/core/src/package/ident.rs index 5e673790ce..f689dde0a2 100644 --- a/components/core/src/package/ident.rs +++ b/components/core/src/package/ident.rs @@ -58,7 +58,11 @@ pub struct PackageIdent { impl PackageIdent { /// Creates a new package identifier - pub fn new>(origin: T, name: T, version: Option, release: Option) -> Self { + pub fn new>(origin: T, + name: T, + version: Option, + release: Option) + -> Self { PackageIdent { origin: origin.into(), name: name.into(), diff --git a/components/core/src/package/install.rs b/components/core/src/package/install.rs index 6c2f8260cf..cf918e62e9 100644 --- a/components/core/src/package/install.rs +++ b/components/core/src/package/install.rs @@ -348,7 +348,10 @@ impl PackageInstall { /// Helper fuction for walk_names. Walks the given name DirEntry for directories and recurses /// into them to find release directories. - fn walk_versions(origin: &String, name: &DirEntry, packages: &mut Vec) -> Result<()> { + fn walk_versions(origin: &String, + name: &DirEntry, + packages: &mut Vec) + -> Result<()> { for version in try!(std::fs::read_dir(name.path())) { let version = try!(version); let name = name.file_name().to_string_lossy().into_owned().to_string(); @@ -370,7 +373,8 @@ impl PackageInstall { for release in try!(std::fs::read_dir(version.path())) { let release = try!(release).file_name().to_string_lossy().into_owned().to_string(); let version = version.file_name().to_string_lossy().into_owned().to_string(); - let ident = PackageIdent::new(origin.clone(), name.clone(), Some(version), Some(release)); + let ident = + PackageIdent::new(origin.clone(), name.clone(), Some(version), Some(release)); packages.push(ident) } Ok(()) diff --git a/components/core/src/service.rs b/components/core/src/service.rs index a120a84c5c..13a41d8b5f 100644 --- a/components/core/src/service.rs +++ b/components/core/src/service.rs @@ -130,9 +130,8 @@ mod test { let actual = ServiceGroup::from_str("kayla.album@flying_colors").unwrap(); assert_eq!(expected, actual); - let expected = ServiceGroup::new("blue-ocean", - "track-from_album", - Some("f-l_y".to_string())); + let expected = + ServiceGroup::new("blue-ocean", "track-from_album", Some("f-l_y".to_string())); let actual = ServiceGroup::from_str("blue-ocean.track-from_album@f-l_y").unwrap(); assert_eq!(expected, actual); } diff --git a/components/core/src/util/perm.rs b/components/core/src/util/perm.rs index c98b90ab0c..a00ea6fb57 100644 --- a/components/core/src/util/perm.rs +++ b/components/core/src/util/perm.rs @@ -12,9 +12,9 @@ use error::{Error, Result}; pub fn set_owner, X: AsRef>(path: T, owner: X) -> Result<()> { let output = try!(Command::new("chown") - .arg(owner.as_ref()) - .arg(path.as_ref()) - .output()); + .arg(owner.as_ref()) + .arg(path.as_ref()) + .output()); match output.status.success() { true => Ok(()), false => Err(Error::PermissionFailed), @@ -26,9 +26,9 @@ pub fn set_owner, X: AsRef>(path: T, owner: X) -> Result<()> // other platform, this code will need to become platform specific. pub fn set_permissions, X: AsRef>(path: T, perm: X) -> Result<()> { let output = try!(Command::new("chmod") - .arg(perm.as_ref()) - .arg(path.as_ref()) - .output()); + .arg(perm.as_ref()) + .arg(path.as_ref()) + .output()); match output.status.success() { true => Ok(()), false => Err(Error::PermissionFailed), diff --git a/components/core/src/util/sys.rs b/components/core/src/util/sys.rs index 171335555f..90d19323a5 100644 --- a/components/core/src/util/sys.rs +++ b/components/core/src/util/sys.rs @@ -11,9 +11,9 @@ use std::process::Command; pub fn ip() -> Result { debug!("Shelling out to determine IP address"); let output = try!(Command::new("sh") - .arg("-c") - .arg("ip route get 8.8.8.8 | awk '{printf \"%s\", $NF; exit}'") - .output()); + .arg("-c") + .arg("ip route get 8.8.8.8 | awk '{printf \"%s\", $NF; exit}'") + .output()); match output.status.success() { true => { debug!("IP address is {}", String::from_utf8_lossy(&output.stdout)); diff --git a/components/depot-client/src/lib.rs b/components/depot-client/src/lib.rs index 676f71d070..1e5cab811f 100644 --- a/components/depot-client/src/lib.rs +++ b/components/depot-client/src/lib.rs @@ -120,9 +120,7 @@ pub fn fetch_package + ?Sized, I: Identifiable>(depot: &str, let path = PathBuf::from(file); Ok(PackageArchive::new(path)) } - Err(Error::HTTP(StatusCode::NotFound)) => { - Err(Error::RemotePackageNotFound(ident.into())) - } + Err(Error::HTTP(StatusCode::NotFound)) => Err(Error::RemotePackageNotFound(ident.into())), Err(e) => Err(e), } } diff --git a/components/depot/tests/functional.rs b/components/depot/tests/functional.rs index 140d0f7f3d..8c7f0bc63a 100644 --- a/components/depot/tests/functional.rs +++ b/components/depot/tests/functional.rs @@ -128,15 +128,21 @@ pub mod depot_tests { let d = docker::depot("test/simple_service"); let ipaddress = d.ipaddress(); - let mut upload = command::sup(&["upload", "test/simple_service", "-u", &format!("http://{}:9632", ipaddress)]) + let mut upload = command::sup(&["upload", + "test/simple_service", + "-u", + &format!("http://{}:9632", ipaddress)]) .unwrap(); upload.wait_with_output(); assert_cmd_exit_code!(upload, [0]); assert_regex!(upload.stdout(), r"Upload Bldr Package (.+)"); assert_regex!(upload.stdout(), r"Uploading from (.+)"); assert_regex!(upload.stdout(), r"Complete"); - let mut install = - command::sup(&["install", "test/simple_service", "-u", &format!("http://{}:9632", ipaddress)]).unwrap(); + let mut install = command::sup(&["install", + "test/simple_service", + "-u", + &format!("http://{}:9632", ipaddress)]) + .unwrap(); install.wait_with_output(); assert_cmd_exit_code!(install, [0]); } diff --git a/components/depot/tests/support/setup.rs b/components/depot/tests/support/setup.rs index fee76ea5a4..4691105d79 100644 --- a/components/depot/tests/support/setup.rs +++ b/components/depot/tests/support/setup.rs @@ -15,10 +15,11 @@ pub fn origin_setup() { pub fn simple_service() { static ONCE: Once = ONCE_INIT; ONCE.call_once(|| { - let mut simple_service = match super::command::plan_build(&super::path::fixture_as_string("simple_service")) { - Ok(cmd) => cmd, - Err(e) => panic!("{:?}", e), - }; + let mut simple_service = + match super::command::plan_build(&super::path::fixture_as_string("simple_service")) { + Ok(cmd) => cmd, + Err(e) => panic!("{:?}", e), + }; simple_service.wait_with_output(); if !simple_service.status.unwrap().success() { panic!("Failed to build simple service"); @@ -32,7 +33,8 @@ pub fn key_install() { } fn dockerize(ident_str: &str) { - let mut install = match super::command::studio_run("hab", &["install", "core/hab-pkg-dockerize"]) { + let mut install = match super::command::studio_run("hab", + &["install", "core/hab-pkg-dockerize"]) { Ok(cmd) => cmd, Err(e) => panic!("{:?}", e), }; @@ -40,12 +42,14 @@ fn dockerize(ident_str: &str) { if !install.status.unwrap().success() { panic!("Failed to install 'core/hab-pkg-dockerize'"); } - let mut docker = - match super::command::studio_run("hab", - &["exec", "core/hab-pkg-dockerize", "hab-pkg-dockerize", ident_str]) { - Ok(cmd) => cmd, - Err(e) => panic!("{:?}", e), - }; + let mut docker = match super::command::studio_run("hab", + &["exec", + "core/hab-pkg-dockerize", + "hab-pkg-dockerize", + ident_str]) { + Ok(cmd) => cmd, + Err(e) => panic!("{:?}", e), + }; docker.wait_with_output(); if !docker.status.unwrap().success() { panic!("Failed to dockerize simple service"); diff --git a/components/director/src/config.rs b/components/director/src/config.rs index 1b7eec42bf..3f70ccb967 100644 --- a/components/director/src/config.rs +++ b/components/director/src/config.rs @@ -65,9 +65,9 @@ impl Config { /// most likely be empty. fn parse_gossip_ip_port(toml: &toml::Value) -> Result> { let ip = toml.lookup("sys.gossip_ip") - .and_then(|s| s.as_str()); + .and_then(|s| s.as_str()); let port = toml.lookup("sys.gossip_port") - .and_then(|s| s.as_integer()); + .and_then(|s| s.as_integer()); match (ip, port) { (Some(ip), Some(port)) => { let ip_port = format!("{}:{}", ip, port); diff --git a/components/director/src/controller.rs b/components/director/src/controller.rs index 78eae9d1cb..88d3cba0b6 100644 --- a/components/director/src/controller.rs +++ b/components/director/src/controller.rs @@ -42,9 +42,9 @@ impl Controller { config: config, exec_ctx: exec_ctx, handler: wonder::actor::Builder::new(SignalNotifier) - .name("signal-handler".to_string()) - .start(()) - .unwrap(), + .name("signal-handler".to_string()) + .start(()) + .unwrap(), children: None, } } diff --git a/components/director/src/main.rs b/components/director/src/main.rs index 62cc43fe36..e1da67af29 100644 --- a/components/director/src/main.rs +++ b/components/director/src/main.rs @@ -27,9 +27,9 @@ //! //! - `ExecContext` //! - A task "execution context". The `ExecContext` is used to -//! decouple service root directory and path to a supervisor executable. -//! Decoupling these values into a struct allows us to easily test -//! `Tasks` + `Controllers`. +//! decouple service root directory and path to a supervisor executable. +//! Decoupling these values into a struct allows us to easily test +//! `Tasks` + `Controllers`. //! //! - `ExecParams` //! - Config values for a `Task` that the `Controller` calculates during diff --git a/components/hab/src/command/artifact.rs b/components/hab/src/command/artifact.rs index 22f1f5b140..fee5057971 100644 --- a/components/hab/src/command/artifact.rs +++ b/components/hab/src/command/artifact.rs @@ -106,7 +106,10 @@ pub mod upload { Ok(()) } - fn upload_into_depot(url: &str, ident: &PackageIdent, mut archive: &mut PackageArchive) -> Result<()> { + fn upload_into_depot(url: &str, + ident: &PackageIdent, + mut archive: &mut PackageArchive) + -> Result<()> { println!("{} {}", Green.bold().paint("↑ Uploading"), archive.path.display()); @@ -142,7 +145,9 @@ pub mod upload { Err(Error::DepotClient(depot_client::Error::HTTP(e))) => { return Err(Error::DepotClient(depot_client::Error::HTTP(e))) } - Err(Error::PackageArchiveMalformed(e)) => return Err(Error::PackageArchiveMalformed(e)), + Err(Error::PackageArchiveMalformed(e)) => { + return Err(Error::PackageArchiveMalformed(e)) + } Err(e) => { println!("Unknown error encountered: {:?}", e); return Err(e); diff --git a/components/hab/src/command/file.rs b/components/hab/src/command/file.rs index 65d5f01d16..6b0b75aeba 100644 --- a/components/hab/src/command/file.rs +++ b/components/hab/src/command/file.rs @@ -24,10 +24,8 @@ pub mod upload { -> Result<()> { println!("{}", Yellow.bold().paint(format!("» Uploading file {}", &file_path.display()))); - let file = try!(GossipFile::from_file_encrypt(&user_pair, - &service_pair, - file_path, - number)); + let file = + try!(GossipFile::from_file_encrypt(&user_pair, &service_pair, file_path, number)); let rumor = hab_gossip::Rumor::gossip_file(file); let mut list = hab_gossip::RumorList::new(); diff --git a/components/hab/src/command/origin.rs b/components/hab/src/command/origin.rs index 7b76e5658c..b4e2572961 100644 --- a/components/hab/src/command/origin.rs +++ b/components/hab/src/command/origin.rs @@ -16,7 +16,11 @@ pub mod key { use common::command::ProgressBar; use error::Result; - pub fn start(depot: &str, origin: &str, revision: Option<&str>, cache: &Path) -> Result<()> { + pub fn start(depot: &str, + origin: &str, + revision: Option<&str>, + cache: &Path) + -> Result<()> { match revision { Some(revision) => { let nwr = format!("{}-{}", origin, revision); @@ -24,17 +28,23 @@ pub mod key { println!("{}", Yellow.bold().paint(msg)); try!(download_key(depot, &nwr, origin, revision, cache)); println!("{}", - Blue.paint(format!("★ Download of {} public origin key completed.", &nwr))); + Blue.paint(format!("★ Download of {} public origin key completed.", + &nwr))); } None => { let msg = format!("» Downloading public origin keys for {}", origin); println!("{}", Yellow.bold().paint(msg)); for key in try!(depot_client::show_origin_keys(depot, origin)) { let nwr = format!("{}-{}", key.get_origin(), key.get_revision()); - try!(download_key(depot, &nwr, key.get_origin(), key.get_revision(), cache)); + try!(download_key(depot, + &nwr, + key.get_origin(), + key.get_revision(), + cache)); } println!("{}", - Blue.paint(format!("★ Download of {} public origin keys completed.", &origin))); + Blue.paint(format!("★ Download of {} public origin keys completed.", + &origin))); } }; Ok(()) @@ -48,7 +58,11 @@ pub mod key { Err(_) => { println!("{} {}", Green.bold().paint("↓ Downloading"), &nwr); let mut progress = ProgressBar::default(); - try!(depot_client::fetch_origin_key(depot, name, rev, cache, Some(&mut progress))); + try!(depot_client::fetch_origin_key(depot, + name, + rev, + cache, + Some(&mut progress))); println!("{} {}", Green.bold().paint("☑ Cached"), &nwr); } } @@ -69,8 +83,12 @@ pub mod key { pub fn start(origin: &str, pair_type: PairType, cache: &Path) -> Result<()> { let latest = try!(SigKeyPair::get_latest_pair_for(origin, cache)); let path = match pair_type { - PairType::Public => try!(SigKeyPair::get_public_key_path(&latest.name_with_rev(), cache)), - PairType::Secret => try!(SigKeyPair::get_secret_key_path(&latest.name_with_rev(), cache)), + PairType::Public => { + try!(SigKeyPair::get_public_key_path(&latest.name_with_rev(), cache)) + } + PairType::Secret => { + try!(SigKeyPair::get_secret_key_path(&latest.name_with_rev(), cache)) + } }; let mut file = try!(File::open(&path)); debug!("Streaming file contents of {} {} to standard out", @@ -94,7 +112,8 @@ pub mod key { Yellow.bold().paint(format!("» Generating origin key for {}", &origin))); let pair = try!(SigKeyPair::generate_pair_for_origin(origin, cache)); println!("{}", - Blue.paint(format!("★ Generated origin key pair {}.", &pair.name_with_rev()))); + Blue.paint(format!("★ Generated origin key pair {}.", + &pair.name_with_rev()))); Ok(()) } } diff --git a/components/hab/src/exec.rs b/components/hab/src/exec.rs index f0bcec50e6..236928c7b1 100644 --- a/components/hab/src/exec.rs +++ b/components/hab/src/exec.rs @@ -40,8 +40,8 @@ pub fn exec_command(command: PathBuf, args: Vec) -> Result<()> { debug!("Calling execv: ({:?}) {:?}", command.display(), &args); let prog_cstring = try!(CString::new(command.as_os_str().as_bytes())); let arg_cstrings = try!(args.into_iter() - .map(|arg| CString::new(arg.as_os_str().as_bytes())) - .collect::, _>>()); + .map(|arg| CString::new(arg.as_os_str().as_bytes())) + .collect::, _>>()); let mut arg_charptrs: Vec<_> = arg_cstrings.iter() .map(|arg| arg.as_bytes_with_nul().as_ptr() as *const i8) .collect(); diff --git a/components/sup/src/census.rs b/components/sup/src/census.rs index f52a6e0fa4..789cd5dd8e 100644 --- a/components/sup/src/census.rs +++ b/components/sup/src/census.rs @@ -638,7 +638,9 @@ impl Census { pub fn has_quorum(&self) -> bool { let total_population = self.total_population(); if total_population % 2 == 0 { - warn!("This census has an even population. If half the membership fails, quorum will never be met, and no leader will be elected. Add another instance to the service group!"); + warn!("This census has an even population. If half the membership fails, quorum will \ + never be met, and no leader will be elected. Add another instance to the \ + service group!"); } let alive_population = self.alive_population() as f32; let total_pop = total_population as f32; diff --git a/components/sup/src/command/start.rs b/components/sup/src/command/start.rs index efc8587627..4f8dc69aa7 100644 --- a/components/sup/src/command/start.rs +++ b/components/sup/src/command/start.rs @@ -91,15 +91,16 @@ pub fn package(config: &Config) -> Result<()> { // // If the operator does not specify a version number they will automatically receive // updates for any releases, regardless of version number, for the started package. - let latest_pkg_data = try!(depot_client::show_package(&url, (*config.package()).clone())); + let latest_pkg_data = + try!(depot_client::show_package(&url, (*config.package()).clone())); let latest_ident: PackageIdent = latest_pkg_data.get_ident().clone().into(); if &latest_ident > package.ident() { outputln!("Downloading latest version from remote: {}", latest_ident); let mut progress = ProgressBar::default(); let archive = try!(depot_client::fetch_package(&url, - latest_ident, - &cache_artifact_path(None), - Some(&mut progress))); + latest_ident, + &cache_artifact_path(None), + Some(&mut progress))); try!(archive.verify(&default_cache_key_path(None))); try!(archive.unpack(None)); } else { @@ -123,7 +124,8 @@ pub fn package(config: &Config) -> Result<()> { Path::new(FS_ROOT_PATH), &cache_artifact_path(None), &default_cache_key_path(None))); - let package = try!(Package::load(&new_pkg_data.get_ident().clone().into(), None)); + let package = try!(Package::load(&new_pkg_data.get_ident().clone().into(), + None)); start_package(package, config) } None => Err(sup_error!(Error::PackageNotFound(config.package().clone()))), diff --git a/components/sup/src/error.rs b/components/sup/src/error.rs index 3aa4c322d6..cec24c7655 100644 --- a/components/sup/src/error.rs +++ b/components/sup/src/error.rs @@ -176,7 +176,10 @@ impl fmt::Display for SupError { Error::KeyNotFound(ref e) => format!("Key not found in key cache: {}", e), Error::MetaFileIO(ref e) => format!("IO error while accessing MetaFile: {:?}", e), Error::NetParseError(ref e) => format!("Can't parse ip:port: {}", e), - Error::NoRunFile => format!("No run file is present for this package; specify a run hook or $pkg_service_run in your plan"), + Error::NoRunFile => { + format!("No run file is present for this package; specify a run hook or \ + $pkg_service_run in your plan") + } Error::NulError(ref e) => format!("{}", e), Error::PackageArchiveMalformed(ref e) => { format!("Package archive was unreadable or contained unexpected contents: {:?}", @@ -197,7 +200,9 @@ impl fmt::Display for SupError { } } Error::SignalFailed => format!("Failed to send a signal to the child process"), - Error::SignalNotifierStarted => format!("Only one instance of a Signal Notifier may be running"), + Error::SignalNotifierStarted => { + format!("Only one instance of a Signal Notifier may be running") + } Error::StrFromUtf8Error(ref e) => format!("{}", e), Error::StringFromUtf8Error(ref e) => format!("{}", e), Error::TomlEncode(ref e) => format!("Failed to encode toml: {}", e), @@ -242,7 +247,9 @@ impl error::Error for SupError { Error::InvalidBinding(_) => "Invalid binding parameter", Error::InvalidKeyParameter(_) => "Key parameter error", Error::InvalidPidFile => "Invalid child process PID file", - Error::InvalidServiceGroupString(_) => "Service group strings must be in service.group format (example: redis.default)", + Error::InvalidServiceGroupString(_) => { + "Service group strings must be in service.group format (example: redis.default)" + } Error::Io(ref err) => err.description(), Error::IPFailed => "Failed to discover the outbound IP address", Error::JsonDecode(_) => "JSON decoding error: {:?}", @@ -250,9 +257,16 @@ impl error::Error for SupError { Error::KeyNotFound(_) => "Key not found in key cache", Error::MetaFileIO(_) => "MetaFile could not be read or written to", Error::NetParseError(_) => "Can't parse IP:port", - Error::NoRunFile => "No run file is present for this package; specify a run hook or $pkg_service_run in your plan", - Error::NulError(_) => "An attempt was made to build a CString with a null byte inside it", - Error::PackageArchiveMalformed(_) => "Package archive was unreadable or had unexpected contents", + Error::NoRunFile => { + "No run file is present for this package; specify a run hook or $pkg_service_run \ + in your plan" + } + Error::NulError(_) => { + "An attempt was made to build a CString with a null byte inside it" + } + Error::PackageArchiveMalformed(_) => { + "Package archive was unreadable or had unexpected contents" + } Error::PackageNotFound(_) => "Cannot find a package", Error::RemotePackageNotFound(_) => "Cannot find a package in any sources", Error::SignalFailed => "Failed to send a signal to the child process", diff --git a/components/sup/src/package/updater.rs b/components/sup/src/package/updater.rs index 8e2e380f24..ca20847263 100644 --- a/components/sup/src/package/updater.rs +++ b/components/sup/src/package/updater.rs @@ -98,7 +98,8 @@ impl GenServer for PackageUpdater { let mut progress = ProgressBar::default(); match depot_client::fetch_package(&state.depot, latest_ident.clone(), - &Path::new(FS_ROOT_PATH).join(CACHE_ARTIFACT_PATH), + &Path::new(FS_ROOT_PATH) + .join(CACHE_ARTIFACT_PATH), Some(&mut progress)) { Ok(archive) => { debug!("Updater downloaded new package to {:?}", archive); diff --git a/components/sup/src/topology/leader.rs b/components/sup/src/topology/leader.rs index 20bdf94e58..4fae3cf902 100644 --- a/components/sup/src/topology/leader.rs +++ b/components/sup/src/topology/leader.rs @@ -103,7 +103,8 @@ fn state_check_for_election(worker: &mut Worker) -> Result<(State, u64)> { // Are you already the leader or a follower? - good on you! Ok((State::CheckForElection, 500)) } else { - debug!("We have a leader, but I am not a leader or a follower; becoming a follower"); + debug!("We have a leader, but I am not a leader or a follower; becoming a \ + follower"); // If you aren't, you should be a follower! Ok((State::BecomeFollower, 0)) } diff --git a/components/sup/src/topology/mod.rs b/components/sup/src/topology/mod.rs index 1e2f99fc6a..4ca5d063e5 100644 --- a/components/sup/src/topology/mod.rs +++ b/components/sup/src/topology/mod.rs @@ -319,7 +319,8 @@ fn run_internal<'a>(sm: &mut StateMachine, SupError>, if try!(service_config.write(&package)) { try!(package.copy_run(&service_config)); try!(package.reconfigure(&service_config)); - outputln!("Restarting because the service config was updated via the census"); + outputln!("Restarting because the service config was updated via the \ + census"); restart_process = true; } } diff --git a/components/sup/src/util/path.rs b/components/sup/src/util/path.rs index 37833ffffe..216fdffb1e 100644 --- a/components/sup/src/util/path.rs +++ b/components/sup/src/util/path.rs @@ -91,9 +91,9 @@ pub fn busybox_paths() -> Result> { Some(dir) => vec![dir.to_path_buf()], None => { let path = bin.to_string_lossy().into_owned(); - outputln!("An unexpected error has occured. BusyBox was found \ - at {}, yet the parent directory could not be computed. \ - Aborting...", + outputln!("An unexpected error has occured. BusyBox was \ + found at {}, yet the parent directory could not \ + be computed. Aborting...", &path); return Err(sup_error!(Error::FileNotFound(path))); } @@ -103,9 +103,9 @@ pub fn busybox_paths() -> Result> { // installed, it's not on `PATH`, what more can we do. Time to give up the // chase. Too bad, we were really trying to be helpful here. None => { - outputln!("A BusyBox installation is required but could not be found. \ - Please install 'core/busybox-static' or put the 'busybox' command \ - on your $PATH. Aborting..."); + outputln!("A BusyBox installation is required but could not be \ + found. Please install 'core/busybox-static' or put the \ + 'busybox' command on your $PATH. Aborting..."); return Err(sup_error!(Error::PackageNotFound(ident))); } } diff --git a/components/sup/tests/bldr_build/mod.rs b/components/sup/tests/bldr_build/mod.rs index b30550ee85..860acdf0ee 100644 --- a/components/sup/tests/bldr_build/mod.rs +++ b/components/sup/tests/bldr_build/mod.rs @@ -32,7 +32,7 @@ fn builds_a_service() { fs::cache_artifact_path(None).to_string_lossy())); let pkg_re = Regex::new(&format!(r"({}/test-bldr_build-0.0.1-\d{{14}}.bldr)", fs::cache_artifact_path(None).to_string_lossy())) - .unwrap(); + .unwrap(); let caps = pkg_re.captures(simple_service.stdout()).unwrap(); if let Some(pkg_path) = caps.at(1) { assert_file_exists_in_studio!(pkg_path); diff --git a/components/sup/tests/functional.rs b/components/sup/tests/functional.rs index d813e49e5e..b971f41497 100644 --- a/components/sup/tests/functional.rs +++ b/components/sup/tests/functional.rs @@ -67,17 +67,17 @@ mod setup { ONCE.call_once(|| { let tempdir = TempDir::new(pkg).unwrap(); let mut copy_cmd = Command::new("cp") - .arg("-r") - .arg(util::path::fixture(pkg)) - .arg(tempdir.path().to_str().unwrap()) - .spawn() - .unwrap(); + .arg("-r") + .arg(util::path::fixture(pkg)) + .arg(tempdir.path().to_str().unwrap()) + .spawn() + .unwrap(); copy_cmd.wait().unwrap(); let mut simple_service = match util::command::plan_build(tempdir.path() - .join(pkg) - .to_str() - .unwrap()) { + .join(pkg) + .to_str() + .unwrap()) { Ok(cmd) => cmd, Err(e) => panic!("{:?}", e), }; diff --git a/components/sup/tests/sup_tests/topology/leader.rs b/components/sup/tests/sup_tests/topology/leader.rs index f092e71de1..a3122e3531 100644 --- a/components/sup/tests/sup_tests/topology/leader.rs +++ b/components/sup/tests/sup_tests/topology/leader.rs @@ -93,9 +93,9 @@ fn elects_on_failure() { let og_leader_id = { sup_a.stop_if_leader() - .or(sup_b.stop_if_leader()) - .or(sup_c.stop_if_leader()) - .expect("We had a leader, but then.. we couldn't find it in our list") + .or(sup_b.stop_if_leader()) + .or(sup_c.stop_if_leader()) + .expect("We had a leader, but then.. we couldn't find it in our list") }; if sup_a.id != og_leader_id { diff --git a/components/sup/tests/util/command.rs b/components/sup/tests/util/command.rs index d24207dac6..9ef82c60e5 100644 --- a/components/sup/tests/util/command.rs +++ b/components/sup/tests/util/command.rs @@ -210,14 +210,12 @@ pub fn dockerize(ident_str: &str) { if !install.status.unwrap().success() { panic!("Failed to install 'core/hab-pkg-dockerize'"); } - let mut docker = match studio_run("hab", - &["exec", - "core/hab-pkg-dockerize", - "hab-pkg-dockerize", - ident_str]) { - Ok(cmd) => cmd, - Err(e) => panic!("{:?}", e), - }; + let mut docker = + match studio_run("hab", + &["exec", "core/hab-pkg-dockerize", "hab-pkg-dockerize", ident_str]) { + Ok(cmd) => cmd, + Err(e) => panic!("{:?}", e), + }; docker.wait_with_output(); if !docker.status.unwrap().success() { panic!("Failed to dockerize simple service"); diff --git a/components/sup/tests/util/docker.rs b/components/sup/tests/util/docker.rs index e64973116f..e96aa350d9 100644 --- a/components/sup/tests/util/docker.rs +++ b/components/sup/tests/util/docker.rs @@ -180,7 +180,7 @@ impl Docker { "{{range .NetworkSettings.Networks}}{{.\ IPAddress}}{{end}}", &self.container_id)]) - .unwrap_or_else(|x| panic!("{:?}", x)); + .unwrap_or_else(|x| panic!("{:?}", x)); cmd.wait_with_output(); let ipaddress = String::from(cmd.stdout().trim()); println!("I have ipaddress {}", &ipaddress); @@ -192,7 +192,7 @@ impl Docker { // Because docker sometimes returns you a container, but the log endpoint fails. thread::sleep(Duration::from_millis(500)); let mut cmd = command::run("docker", &["logs", &self.container_id]) - .unwrap_or_else(|x| panic!("{:?}", x)); + .unwrap_or_else(|x| panic!("{:?}", x)); cmd.wait_with_output(); let output = String::from(cmd.stdout()); let error = String::from(cmd.stderr()); @@ -229,7 +229,7 @@ impl Docker { pub fn stop(&self) { let mut cmd = command::run("docker", &["stop", &self.container_id]) - .unwrap_or_else(|x| panic!("{:?}", x)); + .unwrap_or_else(|x| panic!("{:?}", x)); cmd.wait_with_output(); } @@ -254,12 +254,12 @@ impl Drop for Docker { if thread::panicking() { if let None = env::var_os("HAB_DOCKER_KEEP") { let mut cmd = command::run("docker", &["rm", "-f", &self.container_id]) - .unwrap_or_else(|x| panic!("{:?}", x)); + .unwrap_or_else(|x| panic!("{:?}", x)); cmd.wait_with_output(); } } else { let mut cmd = command::run("docker", &["rm", "-f", &self.container_id]) - .unwrap_or_else(|x| panic!("{:?}", x)); + .unwrap_or_else(|x| panic!("{:?}", x)); cmd.wait_with_output(); } } diff --git a/components/sup/tests/util/supervisor.rs b/components/sup/tests/util/supervisor.rs index c68012bcb3..796429a6d2 100644 --- a/components/sup/tests/util/supervisor.rs +++ b/components/sup/tests/util/supervisor.rs @@ -167,9 +167,9 @@ impl Supervisor { pub fn incarnation(&self) -> u64 { let gossip = self.gossip(); let member_list = gossip.find_path(&["member_list", "members"]) - .unwrap() - .as_object() - .unwrap(); + .unwrap() + .as_object() + .unwrap(); let member = member_list.get(&self.id).unwrap().as_object().unwrap(); member.get("incarnation").unwrap().find("counter").unwrap().as_u64().unwrap() } @@ -177,18 +177,18 @@ impl Supervisor { pub fn has_member(&self, sup: &Supervisor) -> bool { let gossip = self.gossip(); let member_list = gossip.find_path(&["member_list", "members"]) - .unwrap() - .as_object() - .unwrap(); + .unwrap() + .as_object() + .unwrap(); member_list.contains_key(&sup.id) } pub fn health_of_member(&self, sup: &Supervisor) -> String { let gossip = self.gossip(); let member_list = gossip.find_path(&["member_list", "members"]) - .unwrap() - .as_object() - .unwrap(); + .unwrap() + .as_object() + .unwrap(); let member = match member_list.get(&sup.id) { Some(m) => m.as_object().unwrap(), None => return "Nonexistent".to_string(), @@ -200,14 +200,14 @@ impl Supervisor { self.docker .exec(&["/bin/sh", "-l", "-c", &format!("iptables -A INPUT -s {} -j DROP", &sup.ip)]); sup.docker - .exec(&["/bin/sh", "-l", "-c", &format!("iptables -A INPUT -s {} -j DROP", &self.ip)]); + .exec(&["/bin/sh", "-l", "-c", &format!("iptables -A INPUT -s {} -j DROP", &self.ip)]); } pub fn netjoin(&self, sup: &Supervisor) { self.docker .exec(&["/bin/sh", "-l", "-c", &format!("iptables -D INPUT -s {} -j DROP", &sup.ip)]); sup.docker - .exec(&["/bin/sh", "-l", "-c", &format!("iptables -D INPUT -s {} -j DROP", &self.ip)]); + .exec(&["/bin/sh", "-l", "-c", &format!("iptables -D INPUT -s {} -j DROP", &self.ip)]); } pub fn keeps_member_alive(&self, sup: &Supervisor) -> bool { diff --git a/rustfmt.toml b/rustfmt.toml deleted file mode 100644 index 735b58b71b..0000000000 --- a/rustfmt.toml +++ /dev/null @@ -1,2 +0,0 @@ -format_strings = false -max_width = 120