Keep certificate-directory problems on the station window and leave a hand-edit untouched until Save.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-11 19:29:32 +02:00
co-authored by Cursor
parent 775d1b5c82
commit d21e7051d7
8 changed files with 165 additions and 40 deletions
+26 -12
View File
@@ -75,8 +75,19 @@ func (s *Station) Save(form ConfigForm) error {
s.logPath = next.logPath
s.logNotice = next.logNotice
reconnect := wasLoaded && connectionChanged(prev, next)
if reconnect || !wasLoaded {
s.fatal = ""
if next.certFatal != "" {
s.fatal = next.certFatal
s.closeLogLocked()
if next.enableLogging {
s.openLog()
}
if wasLoaded {
s.kickReconnect()
}
} else if reconnect || !wasLoaded {
if !wasLoaded || s.fatal == prev.certFatal {
s.fatal = ""
}
s.closeLogLocked()
if next.enableLogging {
s.openLog()
@@ -98,7 +109,8 @@ func (s *Station) kickReconnect() {
s.cancelDial()
}
if s.conn != nil {
s.conn.Close()
// Close unblocks the session read so Run can dial again.
_ = s.conn.Close()
}
select {
case s.apply <- struct{}{}:
@@ -139,7 +151,7 @@ func readForm(path string) (ConfigForm, string, bool) {
}
return form, fmt.Errorf("the file could not be read: %w", err).Error(), false
}
out, err := parseConfig(path, body)
out, err := parseConfig(path, body, false)
if err != nil {
return out.form, err.Error(), false
}
@@ -170,9 +182,6 @@ func validateForm(configPath string, form ConfigForm) (loaded, ConfigForm, error
return loaded{}, form, err
}
cfg = applyCertificate(cfg, shape, configPath)
if cfg.certFatal != "" {
return loaded{}, form, errors.New(cfg.certFatal)
}
cfg = applyLog(cfg, shape)
stored := ConfigForm{
Host: cfg.host,
@@ -272,11 +281,16 @@ func createExclusive(path string, body []byte) error {
}
_, werr := f.Write(body)
cerr := f.Close()
if werr != nil {
return werr
}
if cerr != nil {
if werr != nil || cerr != nil {
os.Remove(path)
if werr != nil {
return werr
}
return cerr
}
return os.Chmod(path, 0o600)
if err := os.Chmod(path, 0o600); err != nil {
os.Remove(path)
return err
}
return nil
}