diff --git a/scripts/cpp/unify_move_files.py b/scripts/cpp/unify_move_files.py index a5ce1f522dc..abfaa44d9d2 100644 --- a/scripts/cpp/unify_move_files.py +++ b/scripts/cpp/unify_move_files.py @@ -4,6 +4,7 @@ import os import shutil +import filecmp from enum import Enum @@ -79,6 +80,18 @@ def unify_file(fromGame: Game, fromFile: str, toGame: Game, toFile: str): fromGamePath = get_game_path(fromGame) toGamePath = get_game_path(toGame) + # Safety Identical Check + fullFromPath = os.path.join(fromGamePath, os.path.normpath(fromFile)) + fullOppositePath = os.path.join(fromOppositeGamePath, os.path.normpath(fromFile)) + + if not os.path.exists(fullFromPath) or not os.path.exists(fullOppositePath): + print(f"ERROR: One or both files do not exist! Skipping: {fromFile}") + return + + if not filecmp.cmp(fullFromPath, fullOppositePath, shallow=False): + print(f"ERROR: Files are not identical! Skipping to prevent data loss: {fromFile}") + return + fromFirstFolderIndex = fromFile.find("/") toFirstFolderIndex = toFile.find("/") assert(fromFirstFolderIndex > 0)