From f8e5be997b22d47dc749a91dddfa46977b6e94bd Mon Sep 17 00:00:00 2001 From: Nathaniel Ledford Date: Thu, 19 Nov 2026 10:44:53 -0500 Subject: [PATCH] catalog: a failed rename of a streamed write removes its staging file only while it is still ours Co-Authored-By: Claude --- crates/catalog/src/store.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/catalog/src/store.rs b/crates/catalog/src/store.rs index b9a6b724aa..9ae07f2593 100644 --- a/crates/catalog/src/store.rs +++ b/crates/catalog/src/store.rs @@ -307,8 +307,10 @@ impl Store for FsStore { }; check_staging(&self.folder, &tmp, &file)?; if let Err(e) = std::fs::rename(&tmp, self.path(name)) { - // (the staging file is ours: it was just checked) - let _ = std::fs::remove_file(&tmp); + // (as in `write_atomic`: the staging file goes unless it came to belong to another save) + if check_staging(&self.folder, &tmp, &file).is_ok() { + let _ = std::fs::remove_file(&tmp); + } return Err(e); } self.sync_dir();