feat(update): stage 3 rollback on failed apply/start
This commit is contained in:
20
main.py
20
main.py
@@ -844,6 +844,7 @@ class VkChatManager(QMainWindow):
|
|||||||
f"set SRC_DIR={source_dir}",
|
f"set SRC_DIR={source_dir}",
|
||||||
f"set EXE_NAME={exe_name}",
|
f"set EXE_NAME={exe_name}",
|
||||||
f"set TARGET_PID={target_pid}",
|
f"set TARGET_PID={target_pid}",
|
||||||
|
"set BACKUP_DIR=%TEMP%\\anabasis_backup_%RANDOM%%RANDOM%",
|
||||||
":wait_for_exit",
|
":wait_for_exit",
|
||||||
"tasklist /FI \"PID eq %TARGET_PID%\" | find \"%TARGET_PID%\" >nul",
|
"tasklist /FI \"PID eq %TARGET_PID%\" | find \"%TARGET_PID%\" >nul",
|
||||||
"if %ERRORLEVEL% EQU 0 (",
|
"if %ERRORLEVEL% EQU 0 (",
|
||||||
@@ -851,13 +852,26 @@ class VkChatManager(QMainWindow):
|
|||||||
" goto :wait_for_exit",
|
" goto :wait_for_exit",
|
||||||
")",
|
")",
|
||||||
"timeout /t 1 /nobreak >nul",
|
"timeout /t 1 /nobreak >nul",
|
||||||
|
"mkdir \"%BACKUP_DIR%\" >nul 2>&1",
|
||||||
|
"robocopy \"%APP_DIR%\" \"%BACKUP_DIR%\" /E /NFL /NDL /NJH /NJS /NP /R:6 /W:2 >nul",
|
||||||
|
"set RC=%ERRORLEVEL%",
|
||||||
|
"if %RC% GEQ 8 goto :backup_error",
|
||||||
"robocopy \"%SRC_DIR%\" \"%APP_DIR%\" /E /NFL /NDL /NJH /NJS /NP /R:12 /W:2 >nul",
|
"robocopy \"%SRC_DIR%\" \"%APP_DIR%\" /E /NFL /NDL /NJH /NJS /NP /R:12 /W:2 >nul",
|
||||||
"set RC=%ERRORLEVEL%",
|
"set RC=%ERRORLEVEL%",
|
||||||
"if %RC% GEQ 8 goto :copy_error",
|
"if %RC% GEQ 8 goto :rollback",
|
||||||
"start \"\" \"%APP_DIR%\\%EXE_NAME%\"",
|
"start \"\" \"%APP_DIR%\\%EXE_NAME%\"",
|
||||||
|
"timeout /t 2 /nobreak >nul",
|
||||||
|
"tasklist /FI \"IMAGENAME eq %EXE_NAME%\" | find /I \"%EXE_NAME%\" >nul",
|
||||||
|
"if %ERRORLEVEL% NEQ 0 goto :rollback",
|
||||||
|
"rmdir /S /Q \"%BACKUP_DIR%\" >nul 2>&1",
|
||||||
"exit /b 0",
|
"exit /b 0",
|
||||||
":copy_error",
|
":rollback",
|
||||||
"echo Auto-update failed with code %RC% > \"%APP_DIR%\\update_error.log\"",
|
"robocopy \"%BACKUP_DIR%\" \"%APP_DIR%\" /E /NFL /NDL /NJH /NJS /NP /R:6 /W:2 >nul",
|
||||||
|
"start \"\" \"%APP_DIR%\\%EXE_NAME%\"",
|
||||||
|
"echo Auto-update failed. Rollback executed. > \"%APP_DIR%\\update_error.log\"",
|
||||||
|
"exit /b 2",
|
||||||
|
":backup_error",
|
||||||
|
"echo Auto-update failed during backup. Code %RC% > \"%APP_DIR%\\update_error.log\"",
|
||||||
"exit /b %RC%",
|
"exit /b %RC%",
|
||||||
]
|
]
|
||||||
with open(script_path, "w", encoding="utf-8", newline="\r\n") as f:
|
with open(script_path, "w", encoding="utf-8", newline="\r\n") as f:
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ class AuthReloginSmokeTests(unittest.TestCase):
|
|||||||
self.assertIn("def _verify_update_checksum(self, zip_path, checksum_url, download_name):", self.source)
|
self.assertIn("def _verify_update_checksum(self, zip_path, checksum_url, download_name):", self.source)
|
||||||
self.assertIn("def _build_update_script(self, app_dir, source_dir, exe_name, target_pid):", self.source)
|
self.assertIn("def _build_update_script(self, app_dir, source_dir, exe_name, target_pid):", self.source)
|
||||||
self.assertIn("set TARGET_PID=", self.source)
|
self.assertIn("set TARGET_PID=", self.source)
|
||||||
|
self.assertIn("set BACKUP_DIR=", self.source)
|
||||||
|
self.assertIn(":rollback", self.source)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user