Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 5fa9eff

Browse files
committed
Use safeexec to get windows path
1 parent d7b7db4 commit 5fa9eff

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
cdr.dev/slog v1.4.0
77
cdr.dev/wsep v0.0.0-20200728013649-82316a09813f
88
github.com/briandowns/spinner v1.12.0
9+
github.com/cli/safeexec v1.0.0
910
github.com/fatih/color v1.10.0
1011
github.com/google/go-cmp v0.5.5
1112
github.com/gorilla/websocket v1.4.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5O
5454
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
5555
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
5656
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
57+
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
58+
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
5759
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5860
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
5961
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=

internal/cmd/configssh.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ import (
66
"io/ioutil"
77
"net/url"
88
"os"
9-
"os/exec"
109
"os/user"
1110
"path/filepath"
1211
"runtime"
1312
"sort"
1413
"strings"
1514

16-
"cdr.dev/coder-cli/pkg/clog"
17-
15+
"github.com/cli/safeexec"
1816
"github.com/spf13/cobra"
1917
"golang.org/x/xerrors"
2018

2119
"cdr.dev/coder-cli/coder-sdk"
2220
"cdr.dev/coder-cli/internal/coderutil"
21+
"cdr.dev/coder-cli/pkg/clog"
2322
)
2423

2524
const sshStartToken = "# ------------START-CODER-ENTERPRISE-----------"
@@ -181,7 +180,10 @@ func binPath() (string, error) {
181180
// if it isn't.
182181
if runtime.GOOS == "windows" {
183182
binName := filepath.Base(exePath)
184-
pathPath, err := exec.LookPath(exePath)
183+
// We use safeexec instead of os/exec because os/exec returns paths in
184+
// the current working directory, which we will run into very often when
185+
// looking for our own path.
186+
pathPath, err := safeexec.LookPath(binName)
185187
if err != nil {
186188
clog.LogWarn(
187189
"The current executable is not in $PATH.",

0 commit comments

Comments
 (0)