Skip to content

Commit cba8d46

Browse files
committed
Creates Data folder if it doesn't exist
1 parent ea608b8 commit cba8d46

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/storage/file.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::models::Task;
22

3-
use std::fs::{File, OpenOptions};
3+
use std::fs::{File, OpenOptions, create_dir_all};
44
use std::io::{BufReader, BufWriter};
55
use std::path::Path;
66

@@ -17,6 +17,12 @@ pub fn load_tasks() -> Vec<Task> {
1717
}
1818

1919
pub fn save_tasks(tasks: &Vec<Task>) {
20+
21+
if let Some(parent) = Path::new(DATA_FILE).parent(){
22+
if !parent.exists(){
23+
create_dir_all(parent).expect("Failed to create json folder");
24+
}
25+
}
2026
let file = OpenOptions::new()
2127
.create(true)
2228
.write(true)

0 commit comments

Comments
 (0)