导出注册表临时文件改用 create_new 打开
- registry.rs 的 write_atomically 不再用会跟随符号链接的 File::create,改用 O_EXCL 打开临时文件,已存在的链接/残留文件直接失败
This commit is contained in:
@@ -133,7 +133,12 @@ fn write_atomically(path: &Path, text: &str) -> Result<(), RegistryError> {
|
||||
})?;
|
||||
let temp = temp_path(path);
|
||||
let write = || -> std::io::Result<()> {
|
||||
let mut file = fs::File::create(&temp)?;
|
||||
// `create_new`(O_EXCL)不跟随已存在的路径:项目里预先摆好的同名符号链接或残留文件会让
|
||||
// 这次写入直接失败,而不是把链接指向的文件截断成注册表内容。
|
||||
let mut file = fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(&temp)?;
|
||||
file.write_all(text.as_bytes())?;
|
||||
// 替换前落盘:只 flush 的话,崩溃窗口里换过去的可能是还没写完的内容。
|
||||
file.sync_all()
|
||||
|
||||
Reference in New Issue
Block a user