From 21cb8984c3fe18e4ca5f14deecf79cc3d81aea10 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 2 Feb 2016 20:52:14 +0100 Subject: [PATCH] make a clone of the host when iterating over gateways --- pkg/commands/proxy.go | 11 ++++++----- pkg/config/host.go | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/commands/proxy.go b/pkg/commands/proxy.go index c7dc44997..ab8e1d556 100644 --- a/pkg/commands/proxy.go +++ b/pkg/commands/proxy.go @@ -84,23 +84,24 @@ func proxy(host *config.Host, conf *config.Config, dryRun bool) error { Logger.Errorf("Failed to use 'direct' connection: %v", err) } } else { + hostCopy := host.Clone() gatewayHost := conf.GetGatewaySafe(gateway) - err := prepareHostControlPath(host, gatewayHost) + err := prepareHostControlPath(hostCopy, gatewayHost) if err != nil { return err } - if host.ProxyCommand == "" { - host.ProxyCommand = "nc %h %p" + if hostCopy.ProxyCommand == "" { + hostCopy.ProxyCommand = "nc %h %p" } // FIXME: dynamically add "-v" flags - if err = hostPrepare(host); err != nil { + if err = hostPrepare(hostCopy); err != nil { return err } - command := "ssh %name -- " + host.ExpandString(host.ProxyCommand) + command := "ssh %name -- " + hostCopy.ExpandString(hostCopy.ProxyCommand) Logger.Debugf("Using gateway '%s': %s", gateway, command) err = proxyCommand(gatewayHost, command, dryRun) diff --git a/pkg/config/host.go b/pkg/config/host.go index 5a07c387b..30c9102fe 100644 --- a/pkg/config/host.go +++ b/pkg/config/host.go @@ -117,10 +117,17 @@ func NewHost(name string) *Host { } } +// Name returns the name of a host func (h *Host) Name() string { return h.name } +// Clone returns a copy of an existing Host +func (h *Host) Clone() *Host { + newHost := *h + return &newHost +} + // ApplyDefaults ensures a Host is valid by filling the missing fields with defaults func (h *Host) ApplyDefaults(defaults *Host) { // ssh-config fields