Skip to content

Commit 063d08f

Browse files
committed
f Document fsync on unpersisting
1 parent 1ebcc38 commit 063d08f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/io_utils.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,17 @@ impl KVStoreUnpersister for FilesystemPersister {
104104
}
105105

106106
fs::remove_file(&dest_file)?;
107-
let parent_directory = dest_file.parent().unwrap();
108-
let dir_file = fs::OpenOptions::new().read(true).open(parent_directory)?;
109107
#[cfg(not(target_os = "windows"))]
110108
{
109+
let parent_directory = dest_file.parent().unwrap();
110+
let dir_file = fs::OpenOptions::new().read(true).open(parent_directory)?;
111111
unsafe {
112+
// The above call to `fs::remove_file` corresponds to POSIX `unlink`, whose changes
113+
// to the inode might get cached (and hence possibly lost on crash), depending on
114+
// the target platform and file system.
115+
//
116+
// In order to assert we permanently removed the file in question we therefore
117+
// call `fsync` on the parent directory on platforms that support it,
112118
libc::fsync(dir_file.as_raw_fd());
113119
}
114120
}

0 commit comments

Comments
 (0)