Skip to content

Commit ac3d14d

Browse files
committed
fix: single file handle in atomic_write for Windows compatibility
Uses one file handle for create/write/sync instead of separate write then reopen for sync, it just makes sense and it also avoids a race condition on Windows where the file may still be held briefly after closing which leads to test failures in the CI overhaul PR #253.
1 parent 3884314 commit ac3d14d

File tree

1 file changed

+3
-4
lines changed
  • dash-spv/src/storage

1 file changed

+3
-4
lines changed

dash-spv/src/storage/io.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::path::{Path, PathBuf};
44

55
use crate::error::{StorageError, StorageResult};
6+
use tokio::io::AsyncWriteExt;
67

78
/// Get the temporary file path for atomic writes.
89
/// Uses process ID and a counter to ensure uniqueness even with concurrent writes.
@@ -32,10 +33,8 @@ pub(crate) async fn atomic_write(path: &Path, data: &[u8]) -> StorageResult<()>
3233

3334
// Write to temporary file
3435
let write_result = async {
35-
tokio::fs::write(&temp_path, data).await?;
36-
37-
// Sync to disk - open the file and call sync_all
38-
let file = tokio::fs::File::open(&temp_path).await?;
36+
let mut file = tokio::fs::File::create(&temp_path).await?;
37+
file.write_all(data).await?;
3938
file.sync_all().await?;
4039

4140
Ok::<(), std::io::Error>(())

0 commit comments

Comments
 (0)