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
This commit is contained in:
Wataru Otsubo 2024-09-10 21:21:42 +09:00
parent 9e93a085fd
commit 7529d003a6
2 changed files with 18 additions and 15 deletions

View file

@ -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

View file

@ -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<MasterLogResult> {
pub fn parse_file(master_log: PathBuf) -> Result<MasterLogResult> {
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<MasterLogResult> {
let mut lines = file.lines();
let version = {