From 3c0da652c1cca97a20a06976ef1b61a96cbb7c18 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Thu, 11 Feb 2021 13:54:43 +0200 Subject: [PATCH] Make IsWindows never return error --- connection.go | 9 +++++---- ssh.go | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/connection.go b/connection.go index 99bb55c8..1a46b08b 100644 --- a/connection.go +++ b/connection.go @@ -144,12 +144,13 @@ func (c Connection) String() string { } // IsWindows returns true on windows hosts -func (c *Connection) IsWindows() (bool, error) { +func (c *Connection) IsWindows() bool { if !c.IsConnected() { - return false, &NotConnectedError{c} + if client := c.configuredClient(); client != nil { + return client.IsWindows() + } } - - return c.client.IsWindows(), nil + return c.client.IsWindows() } // Exec runs a command on the host diff --git a/ssh.go b/ssh.go index 844cb112..46202717 100644 --- a/ssh.go +++ b/ssh.go @@ -82,10 +82,10 @@ func (c *SSH) Disconnect() { // IsWindows is true when the host is running windows func (c *SSH) IsWindows() bool { - if !c.knowOs { + if !c.knowOs && c.client != nil { + c.isWindows = c.Exec("cmd /c exit 0") == nil c.knowOs = true - c.isWindows = c.Exec("cmd /c exit 0") == nil } return c.isWindows