4
4
"bytes"
5
5
"errors"
6
6
"fmt"
7
+ "github.com/mutagen-io/mutagen/pkg/prompting"
7
8
"io"
8
9
"strings"
9
10
"time"
@@ -14,7 +15,6 @@ import (
14
15
"github.com/mutagen-io/mutagen/pkg/logging"
15
16
"github.com/mutagen-io/mutagen/pkg/mutagen"
16
17
"github.com/mutagen-io/mutagen/pkg/platform/terminal"
17
- "github.com/mutagen-io/mutagen/pkg/prompting"
18
18
streampkg "github.com/mutagen-io/mutagen/pkg/stream"
19
19
)
20
20
@@ -34,49 +34,7 @@ const (
34
34
// installation should be attempted and whether or not the remote environment is
35
35
// cmd.exe-based.
36
36
func connect (logger * logging.Logger , transport Transport , mode , prompter string , cmdExe bool ) (io.ReadWriteCloser , bool , bool , error ) {
37
- // Compute the agent invocation command, relative to the user's home
38
- // directory on the remote. Unless we have reason to assume that this is a
39
- // cmd.exe environment, we construct a path using forward slashes. This will
40
- // work for all POSIX systems and POSIX-like environments on Windows. If we
41
- // know we're hitting a cmd.exe environment, then we use backslashes,
42
- // otherwise the invocation won't work. Watching for cmd.exe to fail on
43
- // commands with forward slashes is actually the way that we detect cmd.exe
44
- // environments.
45
- //
46
- // HACK: We're assuming that none of these path components have spaces in
47
- // them, but since we control all of them, this is probably okay.
48
- //
49
- // HACK: When invoking on Windows systems (whether inside a POSIX
50
- // environment or cmd.exe), we can leave the "exe" suffix off the target
51
- // name. Fortunately this allows us to also avoid having to try the
52
- // combination of forward slashes + ".exe" for Windows POSIX environments.
53
- //
54
- // HACK: When invoking on cmd.exe, we leave off the ~ prefix, since cmd.exe
55
- // doesn't recognize it. In most cases the initial working directory for SSH
56
- // commands is the home directory, but when possible we try to be explicit,
57
- // to work around systems that use a different directory, such as Coder
58
- // workspaces, which allow different initial working directories to be
59
- // configured.
60
- pathSeparator := "/"
61
- pathComponents := []string {filesystem .HomeDirectorySpecial }
62
- if cmdExe {
63
- pathSeparator = "\\ "
64
- pathComponents = nil
65
- }
66
- dataDirectoryName := filesystem .MutagenDataDirectoryName
67
- if mutagen .DevelopmentModeEnabled {
68
- dataDirectoryName = filesystem .MutagenDataDirectoryDevelopmentName
69
- }
70
- pathComponents = append (pathComponents ,
71
- dataDirectoryName ,
72
- filesystem .MutagenAgentsDirectoryName ,
73
- mutagen .Version ,
74
- BaseName ,
75
- )
76
- agentInvocationPath := strings .Join (pathComponents , pathSeparator )
77
-
78
- // Compute the command to invoke.
79
- command := fmt .Sprintf ("%s %s --%s=%s" , agentInvocationPath , mode , FlagLogLevel , logger .Level ())
37
+ command := fmt .Sprintf ("%s %s --%s=%s" , agentInvocationPath (cmdExe ), mode , FlagLogLevel , logger .Level ())
80
38
81
39
// Set up (but do not start) an agent process.
82
40
message := "Connecting to agent (POSIX)..."
@@ -186,6 +144,49 @@ func connect(logger *logging.Logger, transport Transport, mode, prompter string,
186
144
return stream , false , false , nil
187
145
}
188
146
147
+ // agentInvocationPath computes the agent invocation path, relative to the user's home
148
+ // directory on the remote.
149
+ func agentInvocationPath (cmdExe bool ) string {
150
+ // Unless we have reason to assume that this is a cmd.exe environment, we
151
+ // construct a path using forward slashes. This will work for all POSIX
152
+ // systems and POSIX-like environments on Windows. If we know we're hitting
153
+ // a cmd.exe environment, then we use backslashes, otherwise the invocation
154
+ // won't work. Watching for cmd.exe to fail on commands with forward slashes
155
+ // is actually the way that we detect cmd.exe environments.
156
+ //
157
+ // HACK: We're assuming that none of these path components have spaces in
158
+ // them, but since we control all of them, this is probably okay.
159
+ //
160
+ // HACK: When invoking on Windows systems (whether inside a POSIX
161
+ // environment or cmd.exe), we can leave the "exe" suffix off the target
162
+ // name. Fortunately this allows us to also avoid having to try the
163
+ // combination of forward slashes + ".exe" for Windows POSIX environments.
164
+ //
165
+ // HACK: When invoking on cmd.exe, we leave off the ~ prefix, since cmd.exe
166
+ // doesn't recognize it. In most cases the initial working directory for SSH
167
+ // commands is the home directory, but when possible we try to be explicit,
168
+ // to work around systems that use a different directory, such as Coder
169
+ // workspaces, which allow different initial working directories to be
170
+ // configured.
171
+ pathSeparator := "/"
172
+ pathComponents := []string {filesystem .HomeDirectorySpecial }
173
+ if cmdExe {
174
+ pathSeparator = "\\ "
175
+ pathComponents = nil
176
+ }
177
+ dataDirectoryName := filesystem .MutagenDataDirectoryName
178
+ if mutagen .DevelopmentModeEnabled {
179
+ dataDirectoryName = filesystem .MutagenDataDirectoryDevelopmentName
180
+ }
181
+ pathComponents = append (pathComponents ,
182
+ dataDirectoryName ,
183
+ filesystem .MutagenAgentsDirectoryName ,
184
+ mutagen .Version ,
185
+ BaseName ,
186
+ )
187
+ return strings .Join (pathComponents , pathSeparator )
188
+ }
189
+
189
190
// Dial connects to an agent-based endpoint using the specified transport,
190
191
// connection mode, and prompter.
191
192
func Dial (logger * logging.Logger , transport Transport , mode , prompter string ) (io.ReadWriteCloser , error ) {
0 commit comments