From 7529d003a64923067c4fe0f0eb1a83cc5dd07675 Mon Sep 17 00:00:00 2001 From: Wataru Otsubo Date: Tue, 10 Sep 2024 21:21:42 +0900 Subject: [PATCH] refactor: replace MasterLogResult file parse API to use only filename * old one moved to private and used in the new one * for future convert-master-log replacement --- src/main.rs | 14 +------------- src/masterlog.rs | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8338576..448d7cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -353,19 +353,7 @@ fn main() -> Result<()> { master_log, outfile, } => { - let result = { - let file = File::open(master_log.clone())?; - let reader = BufReader::new(file); - MasterLogResult::parse_file( - reader, - master_log - .file_name() - .unwrap() - .to_str() - .unwrap() - .to_string(), - )? - }; + let result = MasterLogResult::parse_file(master_log)?; debug!("{:?}", result); // Print boards to retest diff --git a/src/masterlog.rs b/src/masterlog.rs index 6db76d8..4957da1 100644 --- a/src/masterlog.rs +++ b/src/masterlog.rs @@ -1,6 +1,7 @@ use std::{ collections::BTreeMap, - io::{BufRead, Write}, + fs::File, + io::{BufRead, BufReader, Write}, path::PathBuf, str::FromStr, }; @@ -107,7 +108,21 @@ fn extract_position_id(line: &str) -> Result<(Position, PsbId)> { impl MasterLogResult { /// Parse log file on master jathub. - pub fn parse_file(file: impl BufRead, filename: String) -> Result { + pub fn parse_file(master_log: PathBuf) -> Result { + let file = File::open(master_log.clone())?; + let reader = BufReader::new(file); + MasterLogResult::parse_file_with_filename( + reader, + master_log + .file_name() + .unwrap() + .to_str() + .unwrap() + .to_string(), + ) + } + + fn parse_file_with_filename(file: impl BufRead, filename: String) -> Result { let mut lines = file.lines(); let version = {