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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
- [x] P1.6 — Update storage/runner/format tests + TESTS.md
|
||||||
|
|
||||||
### Phase 2 — PySentry legacy removal
|
### 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.2 — Linux autostart legacy code
|
||||||
- [ ] P2.3 — Delete legacy autostart tests
|
- [ ] P2.3 — Delete legacy autostart tests
|
||||||
- [ ] P2.4 — `.gitignore` / `.dockerignore`
|
- [ ] P2.4 — `.gitignore` / `.dockerignore`
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ func (windowsManager) Status(expectedEnabled bool, executablePath string) (bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const autostartName = "GoSentry"
|
const autostartName = "GoSentry"
|
||||||
const legacyAutostartName = "PySentry"
|
|
||||||
const startupShortcutFile = autostartName + ".lnk"
|
const startupShortcutFile = autostartName + ".lnk"
|
||||||
|
|
||||||
func SetAutostart(enabled bool, executablePath string, iconPath string) error {
|
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
|
// the picture. A Startup-folder shortcut stores target path and arguments as
|
||||||
// separate structured fields, so it avoids quoting bugs and more closely
|
// separate structured fields, so it avoids quoting bugs and more closely
|
||||||
// matches how a user would configure a GUI app by hand.
|
// matches how a user would configure a GUI app by hand.
|
||||||
if err := cleanupLegacyRegistryAutostart(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
shortcutPath, err := startupShortcutPath()
|
shortcutPath, err := startupShortcutPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -57,9 +52,6 @@ func AutostartStatus(expectedEnabled bool, executablePath string) (bool, string)
|
|||||||
_, statErr := os.Stat(shortcutPath)
|
_, statErr := os.Stat(shortcutPath)
|
||||||
if !expectedEnabled {
|
if !expectedEnabled {
|
||||||
if os.IsNotExist(statErr) {
|
if os.IsNotExist(statErr) {
|
||||||
if legacyRegistryAutostartExists() {
|
|
||||||
return false, "Legacy registry autostart exists; save settings to repair"
|
|
||||||
}
|
|
||||||
return true, "Autostart is off"
|
return true, "Autostart is off"
|
||||||
}
|
}
|
||||||
if statErr != nil {
|
if statErr != nil {
|
||||||
@@ -69,9 +61,6 @@ func AutostartStatus(expectedEnabled bool, executablePath string) (bool, string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if os.IsNotExist(statErr) {
|
if os.IsNotExist(statErr) {
|
||||||
if legacyRegistryAutostartExists() {
|
|
||||||
return false, "Legacy registry autostart exists; save settings to repair"
|
|
||||||
}
|
|
||||||
return false, "Autostart shortcut is missing"
|
return false, "Autostart shortcut is missing"
|
||||||
}
|
}
|
||||||
if statErr != nil {
|
if statErr != nil {
|
||||||
@@ -153,11 +142,6 @@ func readShortcut(shortcutPath string) (string, string, error) {
|
|||||||
return target, arguments, nil
|
return target, arguments, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readShortcutTarget(shortcutPath string) (string, error) {
|
|
||||||
target, _, err := readShortcut(shortcutPath)
|
|
||||||
return target, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeIfExists(path string) error {
|
func removeIfExists(path string) error {
|
||||||
err := os.Remove(path)
|
err := os.Remove(path)
|
||||||
if err == nil || os.IsNotExist(err) {
|
if err == nil || os.IsNotExist(err) {
|
||||||
@@ -166,40 +150,6 @@ func removeIfExists(path string) error {
|
|||||||
return err
|
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 {
|
func sameWindowsPath(left string, right string) bool {
|
||||||
left = normalizeWindowsPath(left)
|
left = normalizeWindowsPath(left)
|
||||||
right = normalizeWindowsPath(right)
|
right = normalizeWindowsPath(right)
|
||||||
|
|||||||
@@ -11,20 +11,6 @@ import (
|
|||||||
"gitea.mixdep.ru/mix/gosentry/src/domain"
|
"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) {
|
func TestSameWindowsPathIgnoresCaseAndQuotes(t *testing.T) {
|
||||||
if !sameWindowsPath(`"D:\Apps\GoSentry\gosentry.exe"`, `d:\apps\gosentry\gosentry.exe`) {
|
if !sameWindowsPath(`"D:\Apps\GoSentry\gosentry.exe"`, `d:\apps\gosentry\gosentry.exe`) {
|
||||||
t.Fatal("expected paths to match")
|
t.Fatal("expected paths to match")
|
||||||
|
|||||||
Reference in New Issue
Block a user