Fix stale Sessions: Fingerprint-Reconfig bei Profil-Aenderung, Doku
This commit is contained in:
@@ -25,6 +25,8 @@ final class PTYSession: ObservableObject {
|
||||
var executable = ""
|
||||
var arguments: [String] = []
|
||||
var customEnv: [String: String] = [:]
|
||||
/// Fingerprint der Konfiguration (TerminalManager) — bei Änderung wird neu konfiguriert.
|
||||
var configTag = ""
|
||||
|
||||
private var masterFD: Int32 = -1
|
||||
private var process: Process?
|
||||
@@ -288,8 +290,27 @@ final class TerminalManager: ObservableObject {
|
||||
private var sessions: [UUID: PTYSession] = [:]
|
||||
|
||||
func session(for profile: ConnectionProfile, key: StoredSSHKey?) -> PTYSession {
|
||||
if let existing = sessions[profile.id] { return existing }
|
||||
// Fingerprint aus allem, was die Verbindung bestimmt (inkl. Secret-Wert!):
|
||||
// Ändert der User Host/Passwort/Key, wird neu konfiguriert statt stale weiterzuwählen.
|
||||
let secret = SSHService.loginSecret(for: profile, key: key)
|
||||
let tag = [profile.proto.rawValue, profile.host, "\(profile.port)", profile.username,
|
||||
profile.extraArgs, key?.privateKeyPath ?? "", secret ?? ""].joined(separator: "|")
|
||||
if let existing = sessions[profile.id] {
|
||||
// Laufende Session niemals unter den Füßen wegkonfigurieren — erst Trennen.
|
||||
if existing.isRunning || existing.configTag == tag { return existing }
|
||||
existing.stop()
|
||||
configure(existing, profile: profile, key: key, secret: secret)
|
||||
existing.configTag = tag
|
||||
return existing
|
||||
}
|
||||
let s = PTYSession()
|
||||
configure(s, profile: profile, key: key, secret: secret)
|
||||
s.configTag = tag
|
||||
sessions[profile.id] = s
|
||||
return s
|
||||
}
|
||||
|
||||
private func configure(_ s: PTYSession, profile: ConnectionProfile, key: StoredSSHKey?, secret: String?) {
|
||||
let baseExe: String
|
||||
let baseArgs: [String]
|
||||
if profile.proto == .sftp {
|
||||
@@ -302,7 +323,7 @@ final class TerminalManager: ObservableObject {
|
||||
// Auto-Login nur mit Keychain-Secret + sshpass, sonst interaktiver Prompt im Terminal.
|
||||
// SSH-Agent durchreichen (falls vorhanden): gleiche Keys wie in Terminal.app.
|
||||
let cfg = SSHService.sessionConfig(executable: baseExe, args: baseArgs,
|
||||
password: SSHService.loginSecret(for: profile, key: key),
|
||||
password: secret,
|
||||
sshpassPath: SSHService.findSshpass())
|
||||
s.configure(executable: cfg.executable, arguments: cfg.arguments)
|
||||
var env = cfg.extraEnv
|
||||
@@ -311,8 +332,6 @@ final class TerminalManager: ObservableObject {
|
||||
}
|
||||
s.customEnv = env
|
||||
s.setAutoLogin(cfg.autoLogin)
|
||||
sessions[profile.id] = s
|
||||
return s
|
||||
}
|
||||
|
||||
func close(_ profile: ConnectionProfile) {
|
||||
|
||||
Reference in New Issue
Block a user