Skip to content

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

fix(ragfs): skip vanished localfs entries during listing (#5590)

yu1128-Lc89ded12f237
diff --git a/crates/ragfs/src/plugins/localfs/mod.rs b/crates/ragfs/src/plugins/localfs/mod.rs
index b01334d05..67b50a7dc 100644
--- a/crates/ragfs/src/plugins/localfs/mod.rs
+++ b/crates/ragfs/src/plugins/localfs/mod.rs
@@ -330,6 +330,15 @@ impl LocalFileSystem {
Error::plugin(format!("failed to lock for {operation}: {error}"))
}
+ /// Read directory-entry metadata, tolerating entries removed after readdir yielded them.
+ fn read_entry_metadata(entry: &fs::DirEntry) -> Result<Option<fs::Metadata>> {
+ match entry.metadata() {
+ Ok(metadata) => Ok(Some(metadata)),
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None),
+ Err(error) => Err(Error::plugin(format!("failed to get metadata: {}", error))),
+ }
+ }
+
/// Map local file failures into stable filesystem error categories.
fn map_error(path: &str, error: std::io::Error) -> Error {
if error.kind() == std::io::ErrorKind::NotFound {
@@ -955,9 +964,9 @@ impl FileSystem for LocalFileSystem {
for entry in entries {
let entry =
entry.map_err(|e| Error::plugin(format!("failed to read entry: {}", e)))?;
- let metadata = entry
- .metadata()
- .map_err(|e| Error::plugin(format!("failed to get metadata: {}", e)))?;
+ let Some(metadata) = Self::read_entry_metadata(&entry)? else {
+ continue;
+ };
let name = entry.file_name().to_string_lossy().to_string();
let mode = if metadata.is_dir() { 0o755 } else { 0o644 };
@@ -1278,6 +1287,18 @@ mod tests {
.unwrap());
}
+ #[test]
+ fn test_listing_skips_entry_removed_after_readdir() {
+ let dir = TempDir::new().unwrap();
+ write_file(dir.path(), ".path.ovlock", "lock");
+ let entry = fs::read_dir(dir.path()).unwrap().next().unwrap().unwrap();
+ fs::remove_file(entry.path()).unwrap();
+
+ assert!(LocalFileSystem::read_entry_metadata(&entry)
+ .unwrap()
+ .is_none());
+ }
+
#[tokio::test]
async fn test_localfs_rejects_parent_path_components() {
let dir = TempDir::new().unwrap();