From a7faccef8ab0cfe6a12290810420d05a25afeccd Mon Sep 17 00:00:00 2001 From: mixeme Date: Mon, 22 Jun 2026 22:06:28 +0300 Subject: [PATCH] P2.1: remove PySentry legacy registry autostart from Windows Drop legacyAutostartName, cleanupLegacyRegistryAutostart, legacyRegistryAutostartExists, parseRegistryRunValue, and readShortcutTarget from autostart_windows.go; remove the corresponding legacy registry checks from SetAutostart and AutostartStatus; delete TestParseRegistryRunValue. Co-Authored-By: Claude Sonnet 4.6 --- docs/PRE-RELEASE-TASKS.md | 2 +- src/platform/autostart/autostart_windows.go | 50 ------------------- .../autostart/autostart_windows_test.go | 14 ------ 3 files changed, 1 insertion(+), 65 deletions(-) diff --git a/docs/PRE-RELEASE-TASKS.md b/docs/PRE-RELEASE-TASKS.md index e11be2f..11fc6e0 100644 --- a/docs/PRE-RELEASE-TASKS.md +++ b/docs/PRE-RELEASE-TASKS.md @@ -88,7 +88,7 @@ These land together because both edit `domain/job.go` and `storage/store.go`. - [x] P1.6 — Update storage/runner/format tests + TESTS.md ### Phase 2 — PySentry legacy removal -- [ ] P2.1 — Windows autostart legacy code +- [x] P2.1 — Windows autostart legacy code - [ ] P2.2 — Linux autostart legacy code - [ ] P2.3 — Delete legacy autostart tests - [ ] P2.4 — `.gitignore` / `.dockerignore` diff --git a/src/platform/autostart/autostart_windows.go b/src/platform/autostart/autostart_windows.go index 9493b96..32a7097 100644 --- a/src/platform/autostart/autostart_windows.go +++ b/src/platform/autostart/autostart_windows.go @@ -25,7 +25,6 @@ func (windowsManager) Status(expectedEnabled bool, executablePath string) (bool, } const autostartName = "GoSentry" -const legacyAutostartName = "PySentry" const startupShortcutFile = autostartName + ".lnk" func SetAutostart(enabled bool, executablePath string, iconPath string) error { @@ -34,10 +33,6 @@ func SetAutostart(enabled bool, executablePath string, iconPath string) error { // the picture. A Startup-folder shortcut stores target path and arguments as // separate structured fields, so it avoids quoting bugs and more closely // matches how a user would configure a GUI app by hand. - if err := cleanupLegacyRegistryAutostart(); err != nil { - return err - } - shortcutPath, err := startupShortcutPath() if err != nil { return err @@ -57,9 +52,6 @@ func AutostartStatus(expectedEnabled bool, executablePath string) (bool, string) _, statErr := os.Stat(shortcutPath) if !expectedEnabled { if os.IsNotExist(statErr) { - if legacyRegistryAutostartExists() { - return false, "Legacy registry autostart exists; save settings to repair" - } return true, "Autostart is off" } if statErr != nil { @@ -69,9 +61,6 @@ func AutostartStatus(expectedEnabled bool, executablePath string) (bool, string) } if os.IsNotExist(statErr) { - if legacyRegistryAutostartExists() { - return false, "Legacy registry autostart exists; save settings to repair" - } return false, "Autostart shortcut is missing" } if statErr != nil { @@ -153,11 +142,6 @@ func readShortcut(shortcutPath string) (string, string, error) { return target, arguments, nil } -func readShortcutTarget(shortcutPath string) (string, error) { - target, _, err := readShortcut(shortcutPath) - return target, err -} - func removeIfExists(path string) error { err := os.Remove(path) if err == nil || os.IsNotExist(err) { @@ -166,40 +150,6 @@ func removeIfExists(path string) error { return err } -func cleanupLegacyRegistryAutostart() error { - for _, name := range []string{legacyAutostartName, autostartName} { - command := exec.Command("reg.exe", "delete", `HKCU\Software\Microsoft\Windows\CurrentVersion\Run`, "/v", name, "/f") - winproc.ConfigureHiddenWindow(command) - _ = command.Run() - } - return nil -} - -func legacyRegistryAutostartExists() bool { - for _, name := range []string{legacyAutostartName, autostartName} { - command := exec.Command("reg.exe", "query", `HKCU\Software\Microsoft\Windows\CurrentVersion\Run`, "/v", name) - winproc.ConfigureHiddenWindow(command) - if command.Run() == nil { - return true - } - } - return false -} - -func parseRegistryRunValue(output string) (string, bool) { - for _, line := range strings.Split(output, "\n") { - fields := strings.Fields(strings.TrimSpace(line)) - for index, field := range fields { - if field == "REG_SZ" && index+1 < len(fields) { - value := strings.Join(fields[index+1:], " ") - value = strings.Trim(value, `"`) - return value, value != "" - } - } - } - return "", false -} - func sameWindowsPath(left string, right string) bool { left = normalizeWindowsPath(left) right = normalizeWindowsPath(right) diff --git a/src/platform/autostart/autostart_windows_test.go b/src/platform/autostart/autostart_windows_test.go index c0a0d66..4bfd23c 100644 --- a/src/platform/autostart/autostart_windows_test.go +++ b/src/platform/autostart/autostart_windows_test.go @@ -11,20 +11,6 @@ import ( "gitea.mixdep.ru/mix/gosentry/src/domain" ) -func TestParseRegistryRunValue(t *testing.T) { - output := ` -HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run - GoSentry REG_SZ "D:\Apps\GoSentry\gosentry.exe" -` - value, ok := parseRegistryRunValue(output) - if !ok { - t.Fatal("expected registry value to parse") - } - if value != `D:\Apps\GoSentry\gosentry.exe` { - t.Fatalf("unexpected value: %q", value) - } -} - func TestSameWindowsPathIgnoresCaseAndQuotes(t *testing.T) { if !sameWindowsPath(`"D:\Apps\GoSentry\gosentry.exe"`, `d:\apps\gosentry\gosentry.exe`) { t.Fatal("expected paths to match")