From 6958375f6c476ed011af76e70599408aaf1bd23e Mon Sep 17 00:00:00 2001 From: Andrei Stoica Date: Fri, 6 Oct 2023 11:46:21 -0400 Subject: [PATCH] fixed runtime errors on new pc --- src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 12196fe..7339a43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use comrak::{ComrakExtensionOptions, ComrakOptions, ComrakParseOptions}; use std::borrow::Borrow; use std::collections::HashMap; use std::env; -use std::fs::{read, read_dir, File}; +use std::fs::{read, read_dir, create_dir_all, File, metadata}; use std::io::Write; use std::path::{Path, PathBuf}; use std::process::Command; @@ -39,7 +39,13 @@ fn main() { println!("Could not write to default cfg location: {:#?}", e); } } - let cfg = Config::load(cfg_files.last().unwrap().to_str().unwrap()).unwrap(); + + let cfg_file = match cfg_files.last() { + None => expected_cfg_files[0].to_str().unwrap(), + Some(file) => file.to_str().unwrap() + }; + + let cfg = Config::load(cfg_file).unwrap(); println!("{:#?}", cfg); let data_dir = get_data_dir( @@ -47,8 +53,12 @@ fn main() { .clone() .expect("Could not get notes dir from config"), ); + if !metadata(&data_dir).is_ok() { + create_dir_all(&data_dir); + } println!("dir = {}", data_dir.to_str().unwrap()); + let latest_file = get_latest_file(&data_dir); println!("Latest file: {:?}", latest_file);