Tighten up the warnings

This commit is contained in:
Graham Christensen 2018-01-23 12:54:26 -05:00
parent 30c722ff59
commit 67beebc680
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
5 changed files with 20 additions and 35 deletions

View file

@ -12,7 +12,6 @@ use std::io::BufRead;
use std::io;
use std::process::Child;
use std::thread::JoinHandle;
use std::cmp::{Eq, PartialEq};
pub struct AsyncCmd {
command: Command,

View file

@ -3,15 +3,11 @@ extern crate amqp;
extern crate env_logger;
use std::env;
use std::time::Duration;
use std::thread;
use std::path::PathBuf;
use amqp::Session;
use amqp::Table;
use ofborg::message::{Pr, Repo};
use ofborg::config;
use ofborg::worker;
use ofborg::tasks;

View file

@ -5,7 +5,6 @@ extern crate env_logger;
use uuid::Uuid;
use std::collections::VecDeque;
use std::sync::mpsc::Receiver;
use ofborg::asynccmd::AsyncCmd;
use ofborg::checkout;
use ofborg::message::buildjob;
@ -16,8 +15,6 @@ use ofborg::commentparser;
use ofborg::worker;
use ofborg::notifyworker;
use std::thread;
use std::thread::JoinHandle;
use amqp::protocol::basic::{Deliver, BasicProperties};

View file

@ -6,9 +6,6 @@ use serde_json;
use std::fs;
use std::fs::{OpenOptions, File};
use std::path::{Component, PathBuf};
use std::cmp::{Eq, PartialEq};
use std::hash::Hash;
use std::io::Read;
use ofborg::writetoline;
use ofborg::message::buildlogmsg::BuildLogMsg;
@ -104,7 +101,7 @@ impl LogMessageCollector {
fn open_log(&self, path: PathBuf) -> Result<File, String> {
let dir = path.parent().unwrap();
fs::create_dir_all(dir);
fs::create_dir_all(dir).unwrap();
let attempt = OpenOptions::new()
.append(true)
@ -167,6 +164,7 @@ impl worker::SimpleWorker for LogMessageCollector {
mod tests {
use super::*;
use std::process::Command;
use std::io::Read;
use std::path::Path;
use ofborg::worker::SimpleWorker;
@ -262,7 +260,7 @@ mod tests {
#[test]
fn test_open_log() {
let mut worker = make_worker("open-log");
let worker = make_worker("open-log");
assert!(
worker
.open_log(worker.path_for(&make_from("a")).unwrap())
@ -308,14 +306,14 @@ mod tests {
let mut p = root.clone();
let mut s = String::new();
p.push("routing-key-foo/attempt-id-foo");
File::open(p).unwrap().read_to_string(&mut s);
File::open(p).unwrap().read_to_string(&mut s).unwrap();
assert_eq!(&s, "line-1\n\n\n\nline-5\n");
let mut p = root.clone();
let mut s = String::new();
p.push("routing-key-foo/my-other-attempt");
File::open(p).unwrap().read_to_string(&mut s);
File::open(p).unwrap().read_to_string(&mut s).unwrap();
assert_eq!(&s, "\n\nline-3\n");
}
}

View file

@ -4,33 +4,28 @@ use std::io::Write;
use std::io::Seek;
use std::io::SeekFrom;
use std::fs::File;
use std::io::Read;
pub fn write_to_line(rw: &mut File, line: usize, data: &str) {
rw.seek(SeekFrom::Start(0)).unwrap();
let mut writeout: String = String::new();
{
let reader = BufReader::new(rw.try_clone().unwrap());
let mut lines: Vec<String> = reader
.lines()
.map(|line| match line {
Ok(s) => s,
Err(e) => format!("UTF-8 Decode err: {:?}", e),
})
.collect();
while lines.len() <= line {
lines.push("".to_owned());
}
lines.remove(line);
lines.insert(line, data.to_owned());
writeout = lines.join("\n");
let reader = BufReader::new(rw.try_clone().unwrap());
let mut lines: Vec<String> = reader
.lines()
.map(|line| match line {
Ok(s) => s,
Err(e) => format!("UTF-8 Decode err: {:?}", e),
})
.collect();
while lines.len() <= line {
lines.push("".to_owned());
}
lines.remove(line);
lines.insert(line, data.to_owned());
let writeout = lines.join("\n");
rw.set_len(0).unwrap();
rw.seek(SeekFrom::Start(0)).unwrap();