Add mkdir -p behaviour for output file to simplify harnesses
continuous-integration/drone/push Build is failing
continuous-integration/drone/push Build is failing
This commit is contained in:
+9
-1
@@ -1,4 +1,4 @@
|
||||
use std::fs::File;
|
||||
use std::fs::{create_dir_all, File};
|
||||
use std::path::Path;
|
||||
use rand::Rng;
|
||||
use crate::cli::cli::OutputFormat;
|
||||
@@ -13,6 +13,14 @@ pub fn write<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spawner<P>, S
|
||||
format: OutputFormat,
|
||||
output: &Path,
|
||||
) {
|
||||
// If the parent does not exist (and we are not in the root or operating a relative 1-component-length path))
|
||||
// create it. This greatly simplifies the harness code.
|
||||
if let Some(parent) = output.parent() &&
|
||||
parent.to_str().map(|x| x != "").unwrap_or(true) &&
|
||||
!parent.exists() {
|
||||
create_dir_all(parent).expect("Failed to create path to output");
|
||||
}
|
||||
|
||||
match format {
|
||||
OutputFormat::FullDataJson => write_json_full_data(sys, output),
|
||||
OutputFormat::Positions => write_csv_positions(sys, output),
|
||||
|
||||
Reference in New Issue
Block a user