From 28679204714c17b6c58dcf5a10a14bd535d44868 Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Sat, 23 May 2026 16:33:54 +0800 Subject: [PATCH] Fix DiffPipeline.ApplyPatch: only do atomic replacement when differ leaves tempPath intact (BinaryHandler already handles it) --- .../Pipeline/DiffPipeline.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/c#/GeneralUpdate.Differential/Pipeline/DiffPipeline.cs b/src/c#/GeneralUpdate.Differential/Pipeline/DiffPipeline.cs index 22e6e1c8..eb102b50 100644 --- a/src/c#/GeneralUpdate.Differential/Pipeline/DiffPipeline.cs +++ b/src/c#/GeneralUpdate.Differential/Pipeline/DiffPipeline.cs @@ -240,12 +240,18 @@ private async Task ApplyPatch(string appFilePath, string patchFilePath, Cancella await _binaryDiffer.DirtyAsync(appFilePath, tempPath, patchFilePath, ct); - if (File.Exists(appFilePath)) + // Some differ implementations (e.g., BinaryHandler) perform atomic replacement + // internally: they delete oldPath and copy tempPath back to oldPath, then delete tempPath. + // We only handle the replacement ourselves when the differ left tempPath intact. + if (File.Exists(tempPath)) { - File.SetAttributes(appFilePath, FileAttributes.Normal); - File.Delete(appFilePath); + if (File.Exists(appFilePath)) + { + File.SetAttributes(appFilePath, FileAttributes.Normal); + File.Delete(appFilePath); + } + File.Move(tempPath, appFilePath); } - File.Move(tempPath, appFilePath); } private static void HandleDeleteList(IEnumerable patchFiles, IEnumerable oldFiles)