From 9c48db76b25f53fa6790dc03d31eb7514040c155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Tue, 6 Oct 2026 18:49:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=B3=A8=E5=86=8C=E8=A1=A8?= =?UTF-8?q?=E5=9C=A8=20rename=20=E5=90=8E=20fsync=20=E7=88=B6=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - registry.rs 的 write_atomically 在原子替换后同步父目录,崩溃时目录条目不再可能回退到旧文件 --- .../src-tauri/src/export/registry.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/export/registry.rs b/apps/ai-game-creator-shell/src-tauri/src/export/registry.rs index d7de77b46..656f22d8b 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/export/registry.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/export/registry.rs @@ -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 {