Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit9e56e79

Browse files
committed
Enforce coder-cli in PATH on Windows
1 parentdcfd501 commit9e56e79

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

‎internal/cmd/configssh.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"io/ioutil"
77
"net/url"
88
"os"
9+
"os/exec"
910
"os/user"
1011
"path/filepath"
12+
"runtime"
1113
"sort"
1214
"strings"
1315

@@ -132,8 +134,11 @@ func configSSH(configpath *string, remove *bool, next *bool) func(cmd *cobra.Com
132134
}
133135
}
134136

135-
binPath,err:=os.Executable()
137+
binPath,err:=binPath()
136138
iferr!=nil {
139+
ifruntime.GOOS=="windows" {
140+
returnxerrors.Errorf("Failed to ensure `coder` is in $PATH, please move the `coder` binary to a location in $PATH (such as System32): %w",err)
141+
}
137142
returnxerrors.Errorf("Failed to get executable path: %w",err)
138143
}
139144

@@ -165,6 +170,42 @@ func configSSH(configpath *string, remove *bool, next *bool) func(cmd *cobra.Com
165170
}
166171
}
167172

173+
// binPath returns the path to the coder binary suitable for use in ssh
174+
// ProxyCommand.
175+
funcbinPath() (string,error) {
176+
exePath,err:=os.Executable()
177+
iferr!=nil {
178+
return"",xerrors.Errorf("get executable path: %w",err)
179+
}
180+
181+
// On Windows, the coder-cli executable must be in $PATH for Msys2 and Git
182+
// Bash to function correctly. To prevent weird behavior when people switch
183+
// between the two, we require this for all users.
184+
ifruntime.GOOS=="windows" {
185+
binName:=filepath.Base(exePath)
186+
pathPath,err:=exec.LookPath(exePath)
187+
iferr!=nil {
188+
return"",xerrors.Errorf("locate %q in $PATH: %w",binName,err)
189+
}
190+
191+
// Warn the user if the current executable is not the same as the one in
192+
// $PATH.
193+
iffilepath.Clean(pathPath)!=filepath.Clean(exePath) {
194+
clog.LogWarn(
195+
"The current executable path does not match the executable path found in $PATH.",
196+
"This may lead to problems connecting to your workspace via SSH.",
197+
fmt.Sprintf("\t Current executable path: %q",exePath),
198+
fmt.Sprintf("\tExecutable path in $PATH: %q",pathPath),
199+
)
200+
}
201+
202+
returnbinName,nil
203+
}
204+
205+
// On platforms other than Windows we can use the full path to the binary.
206+
returnexePath,nil
207+
}
208+
168209
// removeOldConfig removes the old ssh configuration from the user's sshconfig.
169210
// Returns true if the config was modified.
170211
funcremoveOldConfig(configstring) (string,bool) {
@@ -230,7 +271,7 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st
230271
returnfmt.Sprintf(
231272
`Host coder.%s
232273
HostName coder.%s
233-
ProxyCommand%s tunnel %s 12213 stdio
274+
ProxyCommand"%s" tunnel %s 12213 stdio
234275
StrictHostKeyChecking no
235276
ConnectTimeout=0
236277
IdentitiesOnly yes

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp