diff --git a/deploy_tool/installer.py b/deploy_tool/installer.py index d010ff1..7015d15 100644 --- a/deploy_tool/installer.py +++ b/deploy_tool/installer.py @@ -118,6 +118,19 @@ def build_mysql_installer_command(installer_path: Path, log_path: Path) -> list[ ] +def build_windows_command_parameters(command: list[str]) -> str: + parameters: list[str] = [] + for argument in command[1:]: + if argument.startswith("CONSOLEARGS="): + value = argument.removeprefix("CONSOLEARGS=") + if '"' in value: + raise ValueError("MySQL CONSOLEARGS 包含不支持的双引号。") + parameters.append(f'CONSOLEARGS="{value}"') + else: + parameters.append(subprocess.list2cmdline([argument])) + return " ".join(parameters) + + def default_mysql_install_log_path() -> Path: local_app_data = os.environ.get("LOCALAPPDATA", "").strip() base = Path(local_app_data) if local_app_data else Path.home() / ".autodeploy" @@ -295,7 +308,7 @@ def run_elevated_command( info.fMask = 0x00000040 # SEE_MASK_NOCLOSEPROCESS info.lpVerb = "runas" info.lpFile = command[0] - info.lpParameters = subprocess.list2cmdline(command[1:]) + info.lpParameters = build_windows_command_parameters(command) info.nShow = 1 # SW_SHOWNORMAL: show the Windows Installer progress window. if not shell_execute(ctypes.byref(info)): error_code = ctypes.windll.kernel32.GetLastError() diff --git a/tests/test_installer.py b/tests/test_installer.py index c801bdd..962322d 100644 --- a/tests/test_installer.py +++ b/tests/test_installer.py @@ -16,6 +16,7 @@ from deploy_tool.installer import ( MYSQL_INSTALLER_SHA256, MYSQL_INSTALLER_URL, build_mysql_installer_command, + build_windows_command_parameters, configure_mysql_weak_password_policy, default_mysql_install_log_path, TOMCAT_VERSION, @@ -125,6 +126,20 @@ class InstallerTests(unittest.TestCase): self.assertEqual(MYSQL_INSTALLER_SHA256, "F60502EB1EE10A9C1D0A26706A627D224DFAE466D82EF3EB9D76A8A718DB9D80") self.assertIn("downloads.mysql.com/archives/", MYSQL_INSTALLER_URL) + def test_formats_mysql_consoleargs_as_an_msi_property_value(self): + command = build_mysql_installer_command( + Path(r"C:\Temp Folder\mysql-installer.msi"), + Path(r"C:\Log Folder\mysql-install.log"), + ) + + parameters = build_windows_command_parameters(command) + + self.assertIn('/i "C:\\Temp Folder\\mysql-installer.msi"', parameters) + self.assertIn('/L*V "C:\\Log Folder\\mysql-install.log"', parameters) + self.assertIn('CONSOLEARGS="install server;8.0.43;x64:*:', parameters) + self.assertIn('root_passwd=123456 --silent --auto-handle-prereqs"', parameters) + self.assertNotIn('"CONSOLEARGS=', parameters) + def test_mysql_is_not_installed_from_stale_winget_manifest(self): with self.assertRaises(ValueError): build_install_command("MySQL")