导出注册表在 rename 后 fsync 父目录
- registry.rs 的 write_atomically 在原子替换后同步父目录,崩溃时目录条目不再可能回退到旧文件
This commit is contained in:
@@ -151,7 +151,13 @@ fn write_atomically(path: &Path, text: &str) -> Result<(), RegistryError> {
|
||||
path: path.to_path_buf(),
|
||||
cause: error.to_string(),
|
||||
}
|
||||
})
|
||||
})?;
|
||||
// rename 只改目录条目:不 fsync 父目录的话,崩溃后「哪个文件才是新的」这件事可能没落盘,
|
||||
// 数据虽然在磁盘上,目录项仍是旧的(甚至没有)。Windows 打不开目录句柄,打不开就跳过。
|
||||
if let Ok(directory) = fs::File::open(parent) {
|
||||
let _ = directory.sync_all();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn temp_path(path: &Path) -> PathBuf {
|
||||
|
||||
Reference in New Issue
Block a user