-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ssh: explicitly set ~ for home directory unless using cmd.exe #1
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. I guess Mutagen doesn't have a great cmd/powershell test suite?
@@ -4,6 +4,7 @@ import ( | |||
"bytes" | |||
"errors" | |||
"fmt" | |||
"github.com/mutagen-io/mutagen/pkg/prompting" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import formatting
pathSeparator := "/" | ||
pathComponents := []string{filesystem.HomeDirectorySpecial} | ||
if cmdExe { | ||
pathSeparator = "\\" | ||
pathComponents = nil | ||
} | ||
dataDirectoryName := filesystem.MutagenDataDirectoryName | ||
if mutagen.DevelopmentModeEnabled { | ||
dataDirectoryName = filesystem.MutagenDataDirectoryDevelopmentName | ||
} | ||
pathComponents = append(pathComponents, | ||
dataDirectoryName, | ||
filesystem.MutagenAgentsDirectoryName, | ||
mutagen.Version, | ||
BaseName, | ||
) | ||
return strings.Join(pathComponents, pathSeparator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this could probably be moved into (another) new function like remoteHomePath(cmdExe bool, components ...string)
so it could be used from both here and install.go
// windowsPowershellCommandNotFoundFragment is a fragment of the error output | ||
// returned on Windows systems running Powershell when a command cannot be | ||
// found. | ||
windowsPowershellCommandNotFoundFragment = "is not recognized as the name of a cmdlet, function, script file, or operable program." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it would break if you have a different OS language, but I guess mutagen was already doing similar error string checks previously and I can't really think of a better way to accomplish this. So it's probably fine for now
Fixes coder/coder#16568
This PR uses an explicit
~
in SSH paths to ensure that the mutagen agent is installed in the home directory, even when the SSH default directory is some other directory, as is the case for some Coder workspaces.Note that this breaks the Docker transport on Linux, since the Docker transport also sets the explicit home directory. If we ever wanted to upstream this, we would need a better fix, but for Coder's purposes we are only interested in SSH-based file sync.
The problem is that while mutagen defines a
Transport
interface, the abstraction is very leaky: in the case of Docker, mutagen actively probes the endpoint to figure out the home directory, and then adds it under the covers. In the case of SSH, mutagen assumes (incorrectly in Coder's case) that the default directory is the home directory. The implementations also differ in how they handle different operating systems, with Docker using probing, while SSH depends on the calling function to retry with different requests that might succeed on different operating systems.For now, I just don't think it's worth making a proper fix that refactors the use of the
Transport
interface, given that we don't care about Docker support. I raised an issue on the main mutagen repo asking if they would consider an PR and got no answer. While the repository is still getting some maintenance, it mainly consists of dependency updates. I don't think the team is able to devote time to considering a larger fix for us.