Skip to content

Commit fd5afdb

Browse files
committed
refactor path component logic into new function
1 parent 9539f24 commit fd5afdb

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

pkg/agent/dial.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"github.com/mutagen-io/mutagen/pkg/prompting"
87
"io"
98
"strings"
109
"time"
@@ -15,6 +14,7 @@ import (
1514
"github.com/mutagen-io/mutagen/pkg/logging"
1615
"github.com/mutagen-io/mutagen/pkg/mutagen"
1716
"github.com/mutagen-io/mutagen/pkg/platform/terminal"
17+
"github.com/mutagen-io/mutagen/pkg/prompting"
1818
streampkg "github.com/mutagen-io/mutagen/pkg/stream"
1919
)
2020

@@ -147,6 +147,21 @@ func connect(logger *logging.Logger, transport Transport, mode, prompter string,
147147
// agentInvocationPath computes the agent invocation path, relative to the user's home
148148
// directory on the remote.
149149
func agentInvocationPath(cmdExe bool) string {
150+
dataDirectoryName := filesystem.MutagenDataDirectoryName
151+
if mutagen.DevelopmentModeEnabled {
152+
dataDirectoryName = filesystem.MutagenDataDirectoryDevelopmentName
153+
}
154+
return remotePathFromHome(cmdExe,
155+
dataDirectoryName,
156+
filesystem.MutagenAgentsDirectoryName,
157+
mutagen.Version,
158+
BaseName,
159+
)
160+
}
161+
162+
// remotePathFromHome constructs a path string from the given components as a list of relative path components from
163+
// the user's home directory. If cmdExe is true, construct a path cmd.exe will understand.
164+
func remotePathFromHome(cmdExe bool, components ...string) string {
150165
// Unless we have reason to assume that this is a cmd.exe environment, we
151166
// construct a path using forward slashes. This will work for all POSIX
152167
// systems and POSIX-like environments on Windows. If we know we're hitting
@@ -174,16 +189,7 @@ func agentInvocationPath(cmdExe bool) string {
174189
pathSeparator = "\\"
175190
pathComponents = nil
176191
}
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-
)
192+
pathComponents = append(pathComponents, components...)
187193
return strings.Join(pathComponents, pathSeparator)
188194
}
189195

pkg/agent/install.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66
"runtime"
7-
"strings"
87

98
"github.com/google/uuid"
109

@@ -76,16 +75,7 @@ func install(logger *logging.Logger, transport Transport, prompter string, cmdEx
7675
if posix {
7776
remoteFileName = "." + remoteFileName
7877
}
79-
// HACK: On cmd.exe systems, the ~ special character is not understood to mean the home directory, so we leave it
80-
// off, and hope that the default copy directory is the home directory.
81-
pathSeparator := "/"
82-
pathComponents := []string{filesystem.HomeDirectorySpecial}
83-
if cmdExe {
84-
pathSeparator = "\\"
85-
pathComponents = nil
86-
}
87-
pathComponents = append(pathComponents, remoteFileName)
88-
fullRemotePath := strings.Join(pathComponents, pathSeparator)
78+
fullRemotePath := remotePathFromHome(cmdExe, remoteFileName)
8979

9080
if err = transport.Copy(agentExecutable, fullRemotePath); err != nil {
9181
return fmt.Errorf("unable to copy agent binary: %w", err)

0 commit comments

Comments
 (0)