Skip to content

Commit

Permalink
Recursively Create Parent Folder of Nodes JSON File
Browse files Browse the repository at this point in the history
  • Loading branch information
esarver committed Apr 1, 2024
1 parent c955a00 commit 0a3c6fe
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion instrument-repl/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use colored::Colorize;
use regex::Regex;
use std::{
fmt::Display,
fs::File,
fs::{self, File},
io::{self, Read, Write},
path::PathBuf,
sync::mpsc::{channel, SendError, Sender, TryRecvError},
Expand Down Expand Up @@ -360,6 +360,21 @@ impl Repl {
}

fn write_json_data(file_path: String, input_line: &str) -> Result<()> {
let path = PathBuf::from(file_path.clone());
let Some(path) = path.parent() else {
return Err(InstrumentReplError::IOError {
source: std::io::Error::new(
io::ErrorKind::InvalidInput,
"given path did not have a containing folder",
),
});
};

// If the path doesn't already exist, recursively create it.
if !path.is_dir() {
fs::create_dir_all(path)?;
}

if let Ok(mut file) = File::create(file_path) {
// Convert the Lua string to JSON
let json_value: serde_json::Value = serde_json::from_str(input_line.trim())?;
Expand Down

0 comments on commit 0a3c6fe

Please sign in to comment.