From d9578d6da2310d722948b6049fb838734249f0bc Mon Sep 17 00:00:00 2001 From: Jonas Martinez <36544012+jonas-martinez@users.noreply.github.com> Date: Sat, 14 Sep 2024 10:46:15 +0200 Subject: [PATCH] fix: No such file or directory on write (#15) --- src/projectmanager/nvim/mod.rs | 1 + src/projectmanager/vscode/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/projectmanager/nvim/mod.rs b/src/projectmanager/nvim/mod.rs index 99aee15..d00e9df 100644 --- a/src/projectmanager/nvim/mod.rs +++ b/src/projectmanager/nvim/mod.rs @@ -58,6 +58,7 @@ pub fn add_project( // Write the updated JSON data back to the file let updated_data = serde_json::to_string_pretty(&entries).expect("Failed to serialize JSON"); + let _ = fs::create_dir_all(&target_path.parent().unwrap()); fs::write(&target_path, updated_data).expect("Unable to write file"); if debug { println!("Entry added {:#?}", new_entry); diff --git a/src/projectmanager/vscode/mod.rs b/src/projectmanager/vscode/mod.rs index 7e8ac4a..907dcc0 100644 --- a/src/projectmanager/vscode/mod.rs +++ b/src/projectmanager/vscode/mod.rs @@ -54,6 +54,7 @@ pub fn add_project( // Write the updated JSON data back to the file let updated_data = serde_json::to_string_pretty(&entries).expect("Failed to serialize JSON"); + let _ = fs::create_dir_all(&target_path.parent().unwrap()); fs::write(&target_path, updated_data).expect("Unable to write file"); if debug { println!("Entry added {:#?}", new_entry);