Skip to content

Commit 847ea8c

Browse files
authored
Perform validation on path for fs_write tool (#638)
1 parent 91778c6 commit 847ea8c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

crates/q_cli/src/cli/chat/tools/fs_write.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::borrow::Cow;
22
use std::io::Write;
3+
use std::path::PathBuf;
34

45
use crossterm::queue;
56
use crossterm::style::{
@@ -8,6 +9,7 @@ use crossterm::style::{
89
};
910
use eyre::{
1011
Result,
12+
bail,
1113
eyre,
1214
};
1315
use fig_os_shim::Context;
@@ -144,7 +146,19 @@ impl FsWrite {
144146
}
145147

146148
pub async fn validate(&mut self, _ctx: &Context) -> Result<()> {
147-
// TODO: check to see if paths are valid
149+
match self {
150+
FsWrite::Create { path, .. } => {
151+
if path.is_empty() {
152+
bail!("Path must not be empty")
153+
};
154+
},
155+
FsWrite::StrReplace { path, .. } | FsWrite::Insert { path, .. } => {
156+
if !PathBuf::from(&path).exists() {
157+
bail!("The provided path must exist in order to replace or insert contents into it")
158+
}
159+
},
160+
}
161+
148162
Ok(())
149163
}
150164
}

0 commit comments

Comments
 (0)