From bd5298564a61dff3d7014c4e0c21ab19ca852280 Mon Sep 17 00:00:00 2001 From: Daisuke Aritomo Date: Thu, 7 Feb 2019 02:52:45 +0900 Subject: [PATCH] Create target directory in `tantivy new` if it doesn't exist --- src/commands/new.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/commands/new.rs b/src/commands/new.rs index 3f44a00..8c724f8 100644 --- a/src/commands/new.rs +++ b/src/commands/new.rs @@ -6,6 +6,7 @@ use tantivy::schema::Cardinality; use tantivy::schema::*; use tantivy::Index; use std::io; +use std::fs; use ansi_term::Style; use ansi_term::Colour::{Red, Blue, Green}; use std::io::Write; @@ -145,6 +146,12 @@ fn run_new(directory: PathBuf) -> tantivy::Result<()> { let schema = schema_builder.build(); let schema_json = format!("{}", serde_json::to_string_pretty(&schema).unwrap()); println!("\n{}\n", Style::new().fg(Green).paint(schema_json)); + match fs::create_dir(&directory) { + Ok(_) => (), + // Proceed here; actual existence of index is checked in Index::create_in_dir + Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => (), + Err(e) => panic!("{:?}", e), + }; Index::create_in_dir(&directory, schema)?; Ok(()) }