From 62c3390d31a5e9f8aa40168eaae2d354617421ec Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 30 Sep 2022 16:05:48 -0700 Subject: [PATCH] use batchmode for non-manual connections. don't allow duplicate aliases for remotes --- pkg/remote/remote.go | 5 ++++- pkg/sstore/dbops.go | 4 ++++ pkg/sstore/updatebus.go | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index ea2ea455..31abc29c 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -770,6 +770,9 @@ func (msh *MShellProc) Launch() { msh.WriteToPtyBuffer("connecting to %s...\n", remoteCopy.RemoteCanonicalName) sshOpts := convertSSHOpts(remoteCopy.SSHOpts) sshOpts.SSHErrorsToTty = true + if remoteCopy.ConnectMode != sstore.ConnectModeManual { + sshOpts.BatchMode = true + } cmdStr := MakeServerCommandStr() ecmd := sshOpts.MakeSSHExecCmd(cmdStr) cmdPty, err := msh.addControllingTty(ecmd) @@ -820,7 +823,7 @@ func (msh *MShellProc) Launch() { } if err != nil { msh.setErrorStatus(err) - msh.WriteToPtyBuffer("*error connecting to remote (uname=%q): %v\n", msh.UName, err) + msh.WriteToPtyBuffer("*error connecting to remote: %v\n", err) return } msh.WriteToPtyBuffer("connected\n") diff --git a/pkg/sstore/dbops.go b/pkg/sstore/dbops.go index 10761cab..65c5c2f7 100644 --- a/pkg/sstore/dbops.go +++ b/pkg/sstore/dbops.go @@ -123,6 +123,10 @@ func UpsertRemote(ctx context.Context, r *RemoteType) error { if tx.Exists(query, r.RemoteCanonicalName) { return fmt.Errorf("remote has duplicate canonicalname '%s', cannot create", r.RemoteCanonicalName) } + query = `SELECT remoteid FROM remote WHERE alias = ?` + if r.RemoteAlias != "" && tx.Exists(query, r.RemoteAlias) { + return fmt.Errorf("remote has duplicate alias '%s', cannot create", r.RemoteAlias) + } query = `SELECT COALESCE(max(remoteidx), 0) FROM remote` maxRemoteIdx := tx.GetInt(query) r.RemoteIdx = int64(maxRemoteIdx + 1) diff --git a/pkg/sstore/updatebus.go b/pkg/sstore/updatebus.go index 49dcc9ee..59b91bfc 100644 --- a/pkg/sstore/updatebus.go +++ b/pkg/sstore/updatebus.go @@ -83,6 +83,7 @@ type RemoteEditType struct { RemoteEdit bool `json:"remoteedit"` RemoteId string `json:"remoteid,omitempty"` ErrorStr string `json:"errorstr,omitempty"` + InfoStr string `json:"infostr,omitempty"` } type InfoMsgType struct {