Skip to content

Commit 8f6b95b

Browse files
committed
sync parent dir after rename
1 parent 8bdfec9 commit 8f6b95b

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/receivers/file/persistence/json_file.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ fn atomic_write(path: &Path, state: &DatabaseState) -> Result<()> {
279279
fs::rename(&temp_path, path)
280280
.map_err(|e| Error::Persistence(format!("failed to rename database file: {}", e)))?;
281281

282+
// Fsync parent directory to ensure the rename (directory entry update) is durable.
283+
// Without this, a power failure could roll back to the old directory state.
284+
if let Some(parent) = path.parent() {
285+
if let Ok(dir) = File::open(parent) {
286+
let _ = dir.sync_all();
287+
}
288+
}
289+
282290
Ok(())
283291
}
284292

0 commit comments

Comments
 (0)