catalog: a failed rename of a streamed write removes its staging file only while it is still ours

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Nathaniel LedfordandClaude committed 2026-11-19 10:44:53 -05:00
1 parent a3cac015c1
commit f8e5be997b
1 file changed
+4 -2
+4 -2
View File
@@ -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();