Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(ragfs): normalize localfs mkdir already exists (#4246)

bot-of-qin-ctx84156432b0b1
diff --git a/crates/ragfs/src/plugins/localfs/mod.rs b/crates/ragfs/src/plugins/localfs/mod.rs
index 6a3ddf27c..928f537ba 100644
--- a/crates/ragfs/src/plugins/localfs/mod.rs
+++ b/crates/ragfs/src/plugins/localfs/mod.rs
@@ -7,7 +7,7 @@ use async_trait::async_trait;
use std::fs;
use std::path::{Path, PathBuf};
-use std::io::{BufRead, BufReader};
+use std::io::{BufRead, BufReader, ErrorKind};
use std::process::{Command, Stdio};
use grep_regex::RegexMatcher;
@@ -905,11 +905,13 @@ impl FileSystem for LocalFileSystem {
}
}
- // Create directory
- fs::create_dir(&local_path)
- .map_err(|e| Error::plugin(format!("failed to create directory: {}", e)))?;
-
- Ok(())
+ match fs::create_dir(&local_path) {
+ Ok(()) => Ok(()),
+ Err(e) if e.kind() == ErrorKind::AlreadyExists => {
+ Err(Error::AlreadyExists(path.to_string()))
+ }
+ Err(e) => Err(Error::plugin(format!("failed to create directory: {}", e))),
+ }
}
async fn remove(&self, path: &str) -> Result<()> {