From 7511eb771bb5752447f807c654968ef69a6dcd87 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 27 Jan 2018 14:41:39 -0500 Subject: [PATCH] clean up whitespace --- ofborg/src/asynccmd.rs | 123 ++++++++++++++++++++-------------- ofborg/src/bin/build-faker.rs | 4 +- ofborg/src/test_scratch.rs | 5 +- 3 files changed, 77 insertions(+), 55 deletions(-) diff --git a/ofborg/src/asynccmd.rs b/ofborg/src/asynccmd.rs index 33389d7..0ea65d8 100644 --- a/ofborg/src/asynccmd.rs +++ b/ofborg/src/asynccmd.rs @@ -27,7 +27,7 @@ pub struct AsyncCmd { } pub struct SpawnedAsyncCmd { - waiter: JoinHandle<(Option>)>, + waiter: JoinHandle<(Option>)>, rx: Receiver, } @@ -41,43 +41,57 @@ enum WaitTarget { #[derive(Debug)] enum WaitResult { Thread(thread::Result), - Process(Result), + Process(Result), } fn reader_tx(read: R, tx: SyncSender) -> thread::JoinHandle<()> { let read = BufReader::new(read); - thread::spawn(move || { - for line in read.lines() { - let to_send: String = match line { - Ok(line) => line, - Err(e) => { - error!("Error reading data in reader_tx: {:?}", e); - "Non-UTF8 data omitted from the log.".to_owned() - } - }; - - if let Err(e) = tx.send(to_send) { - error!("Failed to send log line: {:?}", e); + thread::spawn(move || for line in read.lines() { + let to_send: String = match line { + Ok(line) => line, + Err(e) => { + error!("Error reading data in reader_tx: {:?}", e); + "Non-UTF8 data omitted from the log.".to_owned() } + }; + + if let Err(e) = tx.send(to_send) { + error!("Failed to send log line: {:?}", e); } }) } -fn spawn_join(id: WaitTarget, tx: SyncSender<(WaitTarget, WaitResult)>, waiting_on: thread::JoinHandle) -> thread::JoinHandle<()> { - thread::spawn(move || { - if let Err(e) = tx.send((id, WaitResult::Thread(waiting_on.join()))) { - error!("Failed to send message to the thread waiter: {:?}", e); - } +fn spawn_join( + id: WaitTarget, + tx: SyncSender<(WaitTarget, WaitResult)>, + waiting_on: thread::JoinHandle, +) -> thread::JoinHandle<()> { + thread::spawn(move || if let Err(e) = tx.send(( + id, + WaitResult::Thread( + waiting_on.join(), + ), + )) + { + error!("Failed to send message to the thread waiter: {:?}", e); }) } -fn child_wait(id: WaitTarget, tx: SyncSender<(WaitTarget, WaitResult)>, mut waiting_on: Child) -> thread::JoinHandle<()> { - thread::spawn(move || { - if let Err(e) = tx.send((id, WaitResult::Process(waiting_on.wait()))) { - error!("Failed to send message to the thread waiter: {:?}", e); - } +fn child_wait( + id: WaitTarget, + tx: SyncSender<(WaitTarget, WaitResult)>, + mut waiting_on: Child, +) -> thread::JoinHandle<()> { + thread::spawn(move || if let Err(e) = tx.send(( + id, + WaitResult::Process( + waiting_on.wait(), + ), + )) + { + error!("Failed to send message to the thread waiter: {:?}", e); }) } @@ -103,8 +117,8 @@ impl AsyncCmd { spawn_join( WaitTarget::Stderr, monitor_tx.clone(), - reader_tx(child.stderr.take().unwrap(), proc_tx.clone()) - ) + reader_tx(child.stderr.take().unwrap(), proc_tx.clone()), + ), ); waiters.insert( @@ -112,21 +126,17 @@ impl AsyncCmd { spawn_join( WaitTarget::Stdout, monitor_tx.clone(), - reader_tx(child.stdout.take().unwrap(), proc_tx.clone()) - ) + reader_tx(child.stdout.take().unwrap(), proc_tx.clone()), + ), ); waiters.insert( WaitTarget::Child, - child_wait( - WaitTarget::Child, - monitor_tx.clone(), - child - ) + child_wait(WaitTarget::Child, monitor_tx.clone(), child), ); let head_waiter = thread::spawn(move || { - let mut return_status: Option> = None; + let mut return_status: Option> = None; for (id, interior_result) in monitor_rx.iter() { match waiters.remove(&id) { @@ -147,7 +157,12 @@ impl AsyncCmd { } } - None => { error!("Received notice that {:?} finished, but it isn't being waited on?", id); } + None => { + error!( + "Received notice that {:?} finished, but it isn't being waited on?", + id + ); + } } if waiters.len() == 0 { @@ -156,7 +171,10 @@ impl AsyncCmd { } } - info!("Out of the child waiter recv, with {:?} remaining waits", waiters.len()); + info!( + "Out of the child waiter recv, with {:?} remaining waits", + waiters.len() + ); return return_status; }); @@ -185,12 +203,12 @@ impl SpawnedAsyncCmd { mod tests { use super::AsyncCmd; use std::process::Command; - use std::ffi::{OsStr,OsString}; + use std::ffi::{OsStr, OsString}; use std::os::unix::ffi::OsStrExt; #[test] fn basic_echo_test() { - let mut cmd = Command::new("/bin/sh"); + let mut cmd = Command::new("/bin/sh"); cmd.arg("-c"); cmd.arg("echo hi"); let acmd = AsyncCmd::new(cmd); @@ -204,7 +222,7 @@ mod tests { #[test] fn basic_interpolation_test() { - let mut cmd = Command::new("stdbuf"); + let mut cmd = Command::new("stdbuf"); cmd.arg("-o0"); cmd.arg("-e0"); cmd.arg("bash"); @@ -224,9 +242,11 @@ mod tests { #[test] fn lots_of_small_ios_test() { - let mut cmd = Command::new("/bin/sh"); + let mut cmd = Command::new("/bin/sh"); cmd.arg("-c"); - cmd.arg("for i in `seq 1 100`; do (seq 1 100)& (seq 1 100 >&2)& wait; wait; done"); + cmd.arg( + "for i in `seq 1 100`; do (seq 1 100)& (seq 1 100 >&2)& wait; wait; done", + ); let acmd = AsyncCmd::new(cmd); let mut spawned = acmd.spawn(); @@ -234,7 +254,9 @@ mod tests { assert_eq!(lines.len(), 20000); let thread_result = spawned.wait(); let child_result_opt = thread_result.expect("Thread should exit correctly"); - let child_result = child_result_opt.expect("Thread should have properly properly returned the child's status"); + let child_result = child_result_opt.expect( + "Thread should have properly properly returned the child's status", + ); let exit_status = child_result.expect("The child should have no problem exiting"); assert_eq!(true, exit_status.success()); } @@ -242,7 +264,7 @@ mod tests { #[test] fn lots_of_io_test() { - let mut cmd = Command::new("/bin/sh"); + let mut cmd = Command::new("/bin/sh"); cmd.arg("-c"); cmd.arg("seq 1 100000; seq 1 100000 >&2"); let acmd = AsyncCmd::new(cmd); @@ -252,7 +274,9 @@ mod tests { assert_eq!(lines.len(), 200000); let thread_result = spawned.wait(); let child_result_opt = thread_result.expect("Thread should exit correctly"); - let child_result = child_result_opt.expect("Thread should have properly properly returned the child's status"); + let child_result = child_result_opt.expect( + "Thread should have properly properly returned the child's status", + ); let exit_status = child_result.expect("The child should have no problem exiting"); assert_eq!(true, exit_status.success()); } @@ -263,18 +287,17 @@ mod tests { echos.push(OsStr::from_bytes(&[0xffu8])); echos.push("; echo there;"); - let mut cmd = Command::new("/bin/sh"); + let mut cmd = Command::new("/bin/sh"); cmd.arg("-c"); cmd.arg(echos); let acmd = AsyncCmd::new(cmd); let mut spawned = acmd.spawn(); let lines: Vec = spawned.lines().into_iter().collect(); - assert_eq!(lines, vec![ - "hi", - "Non-UTF8 data omitted from the log.", - "there", - ]); + assert_eq!( + lines, + vec!["hi", "Non-UTF8 data omitted from the log.", "there"] + ); let ret = spawned.wait().unwrap().unwrap().unwrap().success(); assert_eq!(true, ret); } diff --git a/ofborg/src/bin/build-faker.rs b/ofborg/src/bin/build-faker.rs index d0cfe8f..00d1f52 100644 --- a/ofborg/src/bin/build-faker.rs +++ b/ofborg/src/bin/build-faker.rs @@ -19,7 +19,7 @@ use ofborg::commentparser; use ofborg::message::buildjob; -use ofborg::message::{Pr,Repo}; +use ofborg::message::{Pr, Repo}; use ofborg::tasks; @@ -64,7 +64,7 @@ fn main() { repo: repo_msg.clone(), pr: pr_msg.clone(), subset: Some(commentparser::Subset::Nixpkgs), - attrs: vec![ "success".to_owned() ], + attrs: vec!["success".to_owned()], logs: Some((Some("logs".to_owned()), Some(logbackrk.to_lowercase()))), statusreport: Some((None, Some("scratch".to_owned()))), }; diff --git a/ofborg/src/test_scratch.rs b/ofborg/src/test_scratch.rs index 08854ce..4eb7418 100644 --- a/ofborg/src/test_scratch.rs +++ b/ofborg/src/test_scratch.rs @@ -1,9 +1,9 @@ use std::fs; -use std::path::{Path,PathBuf}; +use std::path::{Path, PathBuf}; use std::process::Command; pub struct TestScratch { - root: PathBuf + root: PathBuf, } impl TestScratch { @@ -34,7 +34,6 @@ impl TestScratch { pub fn path(&self) -> PathBuf { self.root.clone() } - } impl Drop for TestScratch {