From b60f26f1ccd68d562e133ba988278dd205ebfa1c Mon Sep 17 00:00:00 2001 From: ArnaudOggy Date: Tue, 15 Oct 2019 16:49:39 +0200 Subject: [PATCH] Manage pathways refactoring --- src/gtfs/mod.rs | 2 +- src/gtfs/read.rs | 13 +++++-------- src/ntfs/mod.rs | 2 +- src/ntfs/read.rs | 10 ++++------ 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/gtfs/mod.rs b/src/gtfs/mod.rs index 3b7e60172..1d30a2639 100644 --- a/src/gtfs/mod.rs +++ b/src/gtfs/mod.rs @@ -296,7 +296,7 @@ where collections.comments = comments; read::manage_stop_times(&mut collections, file_handler)?; read::manage_frequencies(&mut collections, file_handler)?; - collections.pathways = read::read_pathways(&mut collections, file_handler)?; + read::manage_pathways(&mut collections, file_handler)?; collections.levels = read_utils::read_opt_collection(file_handler, "levels.txt")?; collections.sanitize()?; diff --git a/src/gtfs/read.rs b/src/gtfs/read.rs index b8d32ef43..05984e447 100644 --- a/src/gtfs/read.rs +++ b/src/gtfs/read.rs @@ -675,10 +675,7 @@ where Ok((stopareas, stoppoints, stoplocations)) } -pub fn read_pathways( - collections: &mut Collections, - file_handler: &mut H, -) -> Result> +pub fn manage_pathways(collections: &mut Collections, file_handler: &mut H) -> Result<()> where for<'a> &'a mut H: FileHandler, { @@ -687,7 +684,6 @@ where match reader { None => { info!("Skipping {}", file); - Ok(CollectionWithId::new(vec![])?) } Some(reader) => { info!("Reading {}", file); @@ -729,9 +725,10 @@ where })); pathways.push(pathway); } - Ok(CollectionWithId::new(pathways)?) + collections.pathways = CollectionWithId::new(pathways)?; } } + Ok(()) } pub fn read_transfers( @@ -3026,8 +3023,8 @@ mod tests { collections.stop_points = stop_points; collections.stop_locations = stop_locations; - let pathways = super::read_pathways(&mut collections, &mut handler).unwrap(); - assert_eq!(1, pathways.len()); + super::manage_pathways(&mut collections, &mut handler).unwrap(); + assert_eq!(1, collections.pathways.len()); }) } #[test] diff --git a/src/ntfs/mod.rs b/src/ntfs/mod.rs index cd0c00dce..4f1bfbc45 100644 --- a/src/ntfs/mod.rs +++ b/src/ntfs/mod.rs @@ -204,7 +204,7 @@ pub fn read>(path: P) -> Result { read::manage_geometries(&mut collections, path)?; read::manage_feed_infos(&mut collections, path)?; read::manage_stops(&mut collections, path)?; - collections.pathways = read::read_pathways(&mut collections, path)?; + read::manage_pathways(&mut collections, path)?; read::manage_stop_times(&mut collections, path)?; read::manage_codes(&mut collections, path)?; read::manage_comments(&mut collections, path)?; diff --git a/src/ntfs/read.rs b/src/ntfs/read.rs index a72650a66..fcb95245f 100644 --- a/src/ntfs/read.rs +++ b/src/ntfs/read.rs @@ -618,15 +618,12 @@ pub fn manage_companies_on_vj(collections: &mut Collections) -> Result<()> { Ok(()) } -pub fn read_pathways( - collections: &mut Collections, - path: &path::Path, -) -> Result> { +pub fn manage_pathways(collections: &mut Collections, path: &path::Path) -> Result<()> { let file = "pathways.txt"; let pathway_path = path.join(file); if !pathway_path.exists() { info!("Skipping {}", file); - return Ok(CollectionWithId::new(vec![])?); + return Ok(()); } info!("Reading {}", file); @@ -671,7 +668,8 @@ pub fn read_pathways( pathways.push(pathway); } - Ok(CollectionWithId::new(pathways)?) + collections.pathways = CollectionWithId::new(pathways)?; + Ok(()) } #[cfg(test)]