Browse Source

UI/updater: Fix files with similar hashes clashing

Do to multithreading the update process, files of the same hash can
sometimes collide due to race. Ensure the filenames are all unique by
appending an incremented value for each file.
jp9000 3 years ago
parent
commit
7396c211be
1 changed files with 4 additions and 0 deletions
  1. 4 0
      UI/win-update/updater/updater.cpp

+ 4 - 0
UI/win-update/updater/updater.cpp

@@ -885,12 +885,16 @@ static void UpdateWithPatchIfAvailable(const char *name, const char *hash,
 		update.fileSize = size;
 		update.fileSize = size;
 		update.patchable = true;
 		update.patchable = true;
 
 
+		/* ensure the filename is unique */
+		static long increment = 0;
+
 		/* Since the patch depends on the previous version, we can
 		/* Since the patch depends on the previous version, we can
 		 * no longer rely on the temp name being unique to the
 		 * no longer rely on the temp name being unique to the
 		 * new file's hash */
 		 * new file's hash */
 		update.tempPath = tempPath;
 		update.tempPath = tempPath;
 		update.tempPath += L"\\";
 		update.tempPath += L"\\";
 		update.tempPath += patchHashStr;
 		update.tempPath += patchHashStr;
+		update.tempPath += std::to_wstring(increment++);
 		break;
 		break;
 	}
 	}
 }
 }