MCPcopy Index your code
hub / github.com/coder/coder / currentBinPath

Function currentBinPath

cli/configssh.go:840–879  ·  view source on GitHub ↗

currentBinPath returns the path to the coder binary suitable for use in ssh ProxyCommand.

(w io.Writer)

Source from the content-addressed store, hash-verified

838// currentBinPath returns the path to the coder binary suitable for use in ssh
839// ProxyCommand.
840func currentBinPath(w io.Writer) (string, error) {
841 exePath, err := os.Executable()
842 if err != nil {
843 return "", xerrors.Errorf("get executable path: %w", err)
844 }
845
846 binName := filepath.Base(exePath)
847 // We use safeexec instead of os/exec because os/exec returns paths in
848 // the current working directory, which we will run into very often when
849 // looking for our own path.
850 pathPath, err := safeexec.LookPath(binName)
851 // On Windows, the coder-cli executable must be in $PATH for both Msys2/Git
852 // Bash and OpenSSH for Windows (used by Powershell and VS Code) to function
853 // correctly. Check if the current executable is in $PATH, and warn the user
854 // if it isn't.
855 if err != nil && runtime.GOOS == "windows" {
856 cliui.Warn(w,
857 "The current executable is not in $PATH.",
858 "This may lead to problems connecting to your workspace via SSH.",
859 fmt.Sprintf("Please move %q to a location in your $PATH (such as System32) and run `%s config-ssh` again.", binName, binName),
860 )
861 _, _ = fmt.Fprint(w, "\n")
862 // Return the exePath so SSH at least works outside of Msys2.
863 return exePath, nil
864 }
865
866 // Warn the user if the current executable is not the same as the one in
867 // $PATH.
868 if filepath.Clean(pathPath) != filepath.Clean(exePath) {
869 cliui.Warn(w,
870 "The current executable path does not match the executable path found in $PATH.",
871 "This may cause issues connecting to your workspace via SSH.",
872 fmt.Sprintf("\tCurrent executable path: %q", exePath),
873 fmt.Sprintf("\tExecutable path in $PATH: %q", pathPath),
874 )
875 _, _ = fmt.Fprint(w, "\n")
876 }
877
878 return exePath, nil
879}
880
881// diffBytes takes two byte slices and diffs them as if they were in a
882// file named name.

Callers 1

configSSHMethod · 0.85

Calls 2

WarnFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected