From 8ef3fdd03bd6bceb4db7c288118e0abdb3bda1b5 Mon Sep 17 00:00:00 2001 From: Merith Date: Wed, 14 Aug 2019 20:02:10 -0700 Subject: [PATCH 01/23] clean push --- .gitignore | 1 + main.go | 19 +++++++++++++++++++ settings.go | 4 ++++ sshcode.go | 23 ++++++++++++++++++----- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index dc0daa9..52d5d04 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor bin .vscode sshcode +sshcode.exe \ No newline at end of file diff --git a/main.go b/main.go index 2a63211..c31bc9d 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" "os" + "path/filepath" + "runtime" "strings" "time" @@ -77,6 +79,11 @@ func (c *rootCmd) Run(fl *flag.FlagSet) { dir = "~" } + // Get linux relative path if on windows + if runtime.GOOS == "windows" { + dir = gitbashWindowsDir(dir) + } + err := sshCode(host, dir, options{ skipSync: c.skipSync, sshFlags: c.sshFlags, @@ -112,3 +119,15 @@ Arguments: helpTab, ) } + +//This section translates a windows path such as "C:\Users\user" to "\Users\user" +//AND removes the default paths for mingw and git4windows to fix specifying a file path breaking +func gitbashWindowsDir(dir string) (res string) { + res = filepath.ToSlash(dir) + res = strings.Replace(res, "C:", "", -1) + + // If you dont use "C:\mingw64" as the location where you installed mingw, copy this and replace /mingw64 with your install path + res = strings.Replace(res, "/mingw64", "", -1) + res = strings.Replace(res, "/msys", "", -1) + return res +} diff --git a/settings.go b/settings.go index ad962a3..d89ec17 100644 --- a/settings.go +++ b/settings.go @@ -24,6 +24,8 @@ func configDir() (string, error) { path = os.ExpandEnv("$HOME/.config/Code/User/") case "darwin": path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/") + case "windows": + return gitbashWindowsDir(os.ExpandEnv("C:\\Users\\$USERNAME\\AppData\\Roaming\\Code\\User")), nil default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } @@ -39,6 +41,8 @@ func extensionsDir() (string, error) { switch runtime.GOOS { case "linux", "darwin": path = os.ExpandEnv("$HOME/.vscode/extensions/") + case "windows": + return gitbashWindowsDir(os.ExpandEnv("C:\\Users\\$USERNAME\\.vscode\\extensions")), nil default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } diff --git a/sshcode.go b/sshcode.go index ad2235e..112b6b5 100644 --- a/sshcode.go +++ b/sshcode.go @@ -10,6 +10,7 @@ import ( "os/exec" "os/signal" "path/filepath" + "runtime" "strconv" "strings" "syscall" @@ -237,11 +238,14 @@ func openBrowser(url string) { var openCmd *exec.Cmd const ( - macPath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" - wslPath = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" + macPath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + wslPath = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" + msysPath = "/Program Files (x86)/Google/Chrome/Application/chrome.exe" ) switch { + case commandExists("chrome"): + openCmd = exec.Command("chrome", chromeOptions(url)...) case commandExists("google-chrome"): openCmd = exec.Command("google-chrome", chromeOptions(url)...) case commandExists("google-chrome-stable"): @@ -254,6 +258,8 @@ func openBrowser(url string) { openCmd = exec.Command(macPath, chromeOptions(url)...) case pathExists(wslPath): openCmd = exec.Command(wslPath, chromeOptions(url)...) + case pathExists(msysPath): + openCmd = exec.Command(msysPath, chromeOptions(url)...) default: err := browser.OpenURL(url) if err != nil { @@ -308,6 +314,13 @@ func randomPort() (string, error) { // checkSSHDirectory performs sanity and safety checks on sshDirectory, and // returns a new value for o.reuseConnection depending on the checks. func checkSSHDirectory(sshDirectory string, reuseConnection bool) bool { + + if runtime.GOOS == "windows" { + flog.Info("OS is windows, disabling connection reuse feature") + //reuseConnection = false + return false + } + sshDirectoryMode, err := os.Lstat(expandPath(sshDirectory)) if err != nil { if reuseConnection { @@ -483,7 +496,7 @@ func downloadScript(codeServerPath string) string { [ "$(uname -m)" != "x86_64" ] && echo "Unsupported server architecture $(uname -m). code-server only has releases for x86_64 systems." && exit 1 pkill -f %v || true -mkdir -p ~/.local/share/code-server %v +mkdir -p $HOME/.local/share/code-server %v cd %v curlflags="-o latest-linux" if [ -f latest-linux ]; then @@ -494,8 +507,8 @@ curl $curlflags https://codesrv-ci.cdr.sh/latest-linux ln latest-linux %v chmod +x %v`, codeServerPath, - filepath.Dir(codeServerPath), - filepath.Dir(codeServerPath), + filepath.ToSlash(filepath.Dir(codeServerPath)), + filepath.ToSlash(filepath.Dir(codeServerPath)), codeServerPath, codeServerPath, codeServerPath, From 1e63329b814aade200a9296594946063c9a020fb Mon Sep 17 00:00:00 2001 From: Merith Date: Wed, 14 Aug 2019 20:19:59 -0700 Subject: [PATCH 02/23] patched --- sshcode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sshcode.go b/sshcode.go index 112b6b5..0ddd4f6 100644 --- a/sshcode.go +++ b/sshcode.go @@ -449,7 +449,7 @@ func syncExtensions(sshFlags string, host string, back bool) error { return err } - const remoteExtensionsDir = "~/.local/share/code-server/extensions/" + const remoteExtensionsDir = ".local/share/code-server/extensions/" var ( src = localExtensionsDir + "/" From 8346a94f153d28641e4e932c8f79ed74f6f4c4da Mon Sep 17 00:00:00 2001 From: Merith Date: Wed, 14 Aug 2019 20:39:57 -0700 Subject: [PATCH 03/23] fixed stupid error --- settings.go | 4 ++-- sshcode.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/settings.go b/settings.go index d89ec17..c47bad4 100644 --- a/settings.go +++ b/settings.go @@ -25,7 +25,7 @@ func configDir() (string, error) { case "darwin": path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/") case "windows": - return gitbashWindowsDir(os.ExpandEnv("C:\\Users\\$USERNAME\\AppData\\Roaming\\Code\\User")), nil + return gitbashWindowsDir(os.ExpandEnv("/c/Users/$USERNAME/AppData/Roaming/Code/User")), nil default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } @@ -42,7 +42,7 @@ func extensionsDir() (string, error) { case "linux", "darwin": path = os.ExpandEnv("$HOME/.vscode/extensions/") case "windows": - return gitbashWindowsDir(os.ExpandEnv("C:\\Users\\$USERNAME\\.vscode\\extensions")), nil + return gitbashWindowsDir(os.ExpandEnv("/c/Users/$USERNAME/.vscode/extensions")), nil default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } diff --git a/sshcode.go b/sshcode.go index 0ddd4f6..1960dcc 100644 --- a/sshcode.go +++ b/sshcode.go @@ -423,7 +423,7 @@ func syncUserSettings(sshFlags string, host string, back bool) error { return err } - const remoteSettingsDir = "~/.local/share/code-server/User/" + const remoteSettingsDir = ".local/share/code-server/User/" var ( src = localConfDir + "/" From 1066cd9dd2bdb0fb484ac82ac61dd0f42bd76872 Mon Sep 17 00:00:00 2001 From: Merith Date: Fri, 16 Aug 2019 14:35:36 -0700 Subject: [PATCH 04/23] requested changes 8-14-2019 --- .gitignore | 2 +- main.go | 7 ++++--- sshcode.go | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 52d5d04..94251e3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ vendor bin .vscode sshcode -sshcode.exe \ No newline at end of file +sshcode.exe diff --git a/main.go b/main.go index c31bc9d..e6b09c4 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func (c *rootCmd) Run(fl *flag.FlagSet) { dir = "~" } - // Get linux relative path if on windows + // Get linux relative path if on windows. if runtime.GOOS == "windows" { dir = gitbashWindowsDir(dir) } @@ -120,8 +120,9 @@ Arguments: ) } -//This section translates a windows path such as "C:\Users\user" to "\Users\user" -//AND removes the default paths for mingw and git4windows to fix specifying a file path breaking +// This section translates a windows path such as "C:\Users\user" to "\Users\user" +// and removes the default paths for mingw and git4windows to issues when you +// specify a file path to start code-server in. func gitbashWindowsDir(dir string) (res string) { res = filepath.ToSlash(dir) res = strings.Replace(res, "C:", "", -1) diff --git a/sshcode.go b/sshcode.go index 1960dcc..5a6bb90 100644 --- a/sshcode.go +++ b/sshcode.go @@ -317,7 +317,6 @@ func checkSSHDirectory(sshDirectory string, reuseConnection bool) bool { if runtime.GOOS == "windows" { flog.Info("OS is windows, disabling connection reuse feature") - //reuseConnection = false return false } From 635641428d5ccb22d973e3db431c7a34beb99c3b Mon Sep 17 00:00:00 2001 From: Merith Date: Tue, 17 Sep 2019 14:24:52 -0700 Subject: [PATCH 05/23] rewrite path conversion for msys (UNTESTED) --- main.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index c700b11..9175043 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,11 @@ package main import ( "fmt" + "log" "math/rand" "os" - "path/filepath" + "os/exec" + "runtime" "strings" "time" @@ -128,11 +130,15 @@ Arguments: // and removes the default paths for mingw and git4windows to issues when you // specify a file path to start code-server in. func gitbashWindowsDir(dir string) (res string) { - res = filepath.ToSlash(dir) - res = strings.Replace(res, "C:", "", -1) - - // If you dont use "C:\mingw64" as the location where you installed mingw, copy this and replace /mingw64 with your install path - res = strings.Replace(res, "/mingw64", "", -1) - res = strings.Replace(res, "/msys", "", -1) + out, err := exec.Command("mount").Output() + if err != nil { + log.Fatal(err) + } + lines := strings.Split(string(out), "\n") + for _, line := range lines { + if strings.Index(line, "on / type") != -1 { + res = strings.Replace(line, "on / type ntfs (binary,noacl,auto)", "", -1) + } + } return res } From c0a2e2e583f794a94f129b049512ed3639caa677 Mon Sep 17 00:00:00 2001 From: Merith Date: Tue, 17 Sep 2019 18:56:50 -0700 Subject: [PATCH 06/23] rewrite path conversion for msys (WORKING) --- main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 9175043..26a1cec 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ import ( "math/rand" "os" "os/exec" - + "path/filepath" "runtime" "strings" "time" @@ -130,6 +130,7 @@ Arguments: // and removes the default paths for mingw and git4windows to issues when you // specify a file path to start code-server in. func gitbashWindowsDir(dir string) (res string) { + res = filepath.ToSlash(dir) out, err := exec.Command("mount").Output() if err != nil { log.Fatal(err) @@ -137,8 +138,9 @@ func gitbashWindowsDir(dir string) (res string) { lines := strings.Split(string(out), "\n") for _, line := range lines { if strings.Index(line, "on / type") != -1 { - res = strings.Replace(line, "on / type ntfs (binary,noacl,auto)", "", -1) + line = strings.Replace(line, "on / type ntfs (binary,noacl,auto)", "", -1) } + res = strings.Replace(res, line, "", -1) } return res } From b0b134abc3f5bdaafc351b9e237372d9d827031b Mon Sep 17 00:00:00 2001 From: Merith Date: Tue, 1 Oct 2019 19:34:40 -0700 Subject: [PATCH 07/23] fix ghost path creation --- sshcode.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sshcode.go b/sshcode.go index 0f1c493..3b6ed38 100644 --- a/sshcode.go +++ b/sshcode.go @@ -560,6 +560,9 @@ chmod +x %v`, func ensureDir(path string) error { _, err := os.Stat(path) if os.IsNotExist(err) { + if runtime.GOOS == "windows" && strings.HasPrefix(path, "/c/") { + path = path[3:] + } err = os.MkdirAll(path, 0750) } From 3675d803937aa59c67399148f1e93008b2af071b Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Wed, 2 Oct 2019 09:17:27 -0700 Subject: [PATCH 08/23] Fix opening remote path (UNTESTED) --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 26a1cec..21bc22d 100644 --- a/main.go +++ b/main.go @@ -138,9 +138,9 @@ func gitbashWindowsDir(dir string) (res string) { lines := strings.Split(string(out), "\n") for _, line := range lines { if strings.Index(line, "on / type") != -1 { - line = strings.Replace(line, "on / type ntfs (binary,noacl,auto)", "", -1) + line = strings.Replace(line, " on / type ntfs (binary,noacl,auto)", "", -1) } - res = strings.Replace(res, line, "", -1) + res = strings.TrimPrefix(dir, line) } return res } From 2a129903cba7b7485f48706881031a4ed496aa4f Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Sat, 2 Nov 2019 21:24:39 -0700 Subject: [PATCH 09/23] Fix windows sending literal string / pass travis --- settings.go | 16 ++++++++++++++++ sshcode.go | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/settings.go b/settings.go index c47bad4..f978931 100644 --- a/settings.go +++ b/settings.go @@ -48,3 +48,19 @@ func extensionsDir() (string, error) { } return filepath.Clean(path), nil } + +func windowsVarFix(input string) string { + var remoteSettingsDir = "~/.local/share/code-server/User/" + var remoteExtensionsDir = "~/.local/share/code-server/extensions/" + if runtime.GOOS == "windows" { + remoteSettingsDir = ".local/share/code-server/User/" + remoteExtensionsDir = ".local/share/code-server/extensions/" + } + + if input == "remoteSettingsDir" { + return remoteSettingsDir + } else if input == "remoteExtensionsDir" { + return remoteExtensionsDir + } + return "" +} diff --git a/sshcode.go b/sshcode.go index e6d6391..ffe0286 100644 --- a/sshcode.go +++ b/sshcode.go @@ -463,8 +463,8 @@ func syncUserSettings(sshFlags string, host string, back bool) error { return err } - const remoteSettingsDir = ".local/share/code-server/User/" - + //const remoteSettingsDir = ".local/share/code-server/User/" + var remoteSettingsDir = windowsVarFix("remoteSettingsDir") var ( src = localConfDir + "/" dest = host + ":" + remoteSettingsDir @@ -489,7 +489,8 @@ func syncExtensions(sshFlags string, host string, back bool) error { return err } - const remoteExtensionsDir = ".local/share/code-server/extensions/" + //const remoteExtensionsDir = ".local/share/code-server/extensions/" + var remoteExtensionsDir = windowsVarFix("remoteExtensionsDir") var ( src = localExtensionsDir + "/" From fb3925132f72cacfeb5f7a509ca9c62c300cf9c5 Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Mon, 11 Nov 2019 10:47:19 -0800 Subject: [PATCH 10/23] Merged Eargollo PR Manually --- main.go | 44 ++++++++++++++++++++++++++++++++++++++------ settings.go | 4 ++-- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 21bc22d..ef30fb6 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,9 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "runtime" + "sort" "strings" "time" @@ -27,6 +29,8 @@ var ( helpTab = strings.Repeat(" ", helpTabWidth) // version is overwritten by ci/build.sh. version string + res string + dir string ) func main() { @@ -126,21 +130,49 @@ Arguments: ) } -// This section translates a windows path such as "C:\Users\user" to "\Users\user" +// This section translates a windows path such as "C:\Users\user" to "/Users/user" // and removes the default paths for mingw and git4windows to issues when you // specify a file path to start code-server in. -func gitbashWindowsDir(dir string) (res string) { - res = filepath.ToSlash(dir) +func gitbashWindowsDir(dir string) string { + if dir == "~" { //Special case + return "~/" + } + mountPoints := gitbashMountPointsAndHome() + + // Apply mount points + absDir, _ := filepath.Abs(dir) + absDir = filepath.ToSlash(absDir) + for _, mp := range mountPoints { + if strings.HasPrefix(absDir, mp[0]) { + resolved := strings.Replace(absDir, mp[0], mp[1], 1) + flog.Info("Resolved windows path '%s' to '%s", dir, resolved) + return resolved + } + } + return dir +} + +// This function returns an array with MINGW64 mount points including relative home dir +func gitbashMountPointsAndHome() [][]string { + // Initialize mount points with home dir + mountPoints := [][]string{{filepath.ToSlash(os.Getenv("HOME")), "~"}} + // Load mount points out, err := exec.Command("mount").Output() if err != nil { log.Fatal(err) } lines := strings.Split(string(out), "\n") + var mountRx = regexp.MustCompile(`^(.*) on (.*) type`) for _, line := range lines { - if strings.Index(line, "on / type") != -1 { - line = strings.Replace(line, " on / type ntfs (binary,noacl,auto)", "", -1) + extract := mountRx.FindStringSubmatch(line) + if len(extract) > 0 { + mountPoints = append(mountPoints, []string{extract[1], extract[2]}) } res = strings.TrimPrefix(dir, line) } - return res + // Sort by size to get more restrictive mount points first + sort.Slice(mountPoints, func(i, j int) bool { + return len(mountPoints[i][0]) > len(mountPoints[j][0]) + }) + return mountPoints } diff --git a/settings.go b/settings.go index f978931..6042b04 100644 --- a/settings.go +++ b/settings.go @@ -25,7 +25,7 @@ func configDir() (string, error) { case "darwin": path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/") case "windows": - return gitbashWindowsDir(os.ExpandEnv("/c/Users/$USERNAME/AppData/Roaming/Code/User")), nil + return os.ExpandEnv("/c/Users/$USERNAME/AppData/Roaming/Code/User"), nil default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } @@ -42,7 +42,7 @@ func extensionsDir() (string, error) { case "linux", "darwin": path = os.ExpandEnv("$HOME/.vscode/extensions/") case "windows": - return gitbashWindowsDir(os.ExpandEnv("/c/Users/$USERNAME/.vscode/extensions")), nil + return os.ExpandEnv("/c/Users/$USERNAME/.vscode/extensions"), nil default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } From 8bff186b9d67c1cc27c0182acaf3928599c8392e Mon Sep 17 00:00:00 2001 From: Aeterne Satiatus Date: Mon, 11 Nov 2019 23:38:40 +0000 Subject: [PATCH 11/23] prevent lint.sh and ensuremod.sh from failing in travis --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index ef30fb6..3d04b04 100644 --- a/main.go +++ b/main.go @@ -29,8 +29,8 @@ var ( helpTab = strings.Repeat(" ", helpTabWidth) // version is overwritten by ci/build.sh. version string - res string - dir string + res string + dir string ) func main() { From b895d1b0c5cd2e08707fc3465cc548ec389d79c1 Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Mon, 11 Nov 2019 17:22:19 -0800 Subject: [PATCH 12/23] Fixed Chrome, renamed 'msysPath' to 'winPath' --- sshcode.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sshcode.go b/sshcode.go index ffe0286..b9ed77d 100644 --- a/sshcode.go +++ b/sshcode.go @@ -265,9 +265,9 @@ func openBrowser(url string) { var openCmd *exec.Cmd const ( - macPath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" - wslPath = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" - msysPath = "/Program Files (x86)/Google/Chrome/Application/chrome.exe" + macPath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + wslPath = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" + winPath = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" ) switch { @@ -285,8 +285,8 @@ func openBrowser(url string) { openCmd = exec.Command(macPath, chromeOptions(url)...) case pathExists(wslPath): openCmd = exec.Command(wslPath, chromeOptions(url)...) - case pathExists(msysPath): - openCmd = exec.Command(msysPath, chromeOptions(url)...) + case pathExists(winPath): + openCmd = exec.Command(winPath, chromeOptions(url)...) default: err := browser.OpenURL(url) if err != nil { From 73309c76253cfe48ceb997f5ba79102d5f0f7448 Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Sat, 30 Nov 2019 08:50:36 -0800 Subject: [PATCH 13/23] fix msys-support completely, fully functional --- main.go | 54 ------------------------------- settings.go | 12 ++----- sshcode.go | 91 +++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 83 insertions(+), 74 deletions(-) diff --git a/main.go b/main.go index 3d04b04..674f983 100644 --- a/main.go +++ b/main.go @@ -2,14 +2,9 @@ package main import ( "fmt" - "log" "math/rand" "os" - "os/exec" - "path/filepath" - "regexp" "runtime" - "sort" "strings" "time" @@ -29,8 +24,6 @@ var ( helpTab = strings.Repeat(" ", helpTabWidth) // version is overwritten by ci/build.sh. version string - res string - dir string ) func main() { @@ -129,50 +122,3 @@ Arguments: helpTab, ) } - -// This section translates a windows path such as "C:\Users\user" to "/Users/user" -// and removes the default paths for mingw and git4windows to issues when you -// specify a file path to start code-server in. -func gitbashWindowsDir(dir string) string { - if dir == "~" { //Special case - return "~/" - } - mountPoints := gitbashMountPointsAndHome() - - // Apply mount points - absDir, _ := filepath.Abs(dir) - absDir = filepath.ToSlash(absDir) - for _, mp := range mountPoints { - if strings.HasPrefix(absDir, mp[0]) { - resolved := strings.Replace(absDir, mp[0], mp[1], 1) - flog.Info("Resolved windows path '%s' to '%s", dir, resolved) - return resolved - } - } - return dir -} - -// This function returns an array with MINGW64 mount points including relative home dir -func gitbashMountPointsAndHome() [][]string { - // Initialize mount points with home dir - mountPoints := [][]string{{filepath.ToSlash(os.Getenv("HOME")), "~"}} - // Load mount points - out, err := exec.Command("mount").Output() - if err != nil { - log.Fatal(err) - } - lines := strings.Split(string(out), "\n") - var mountRx = regexp.MustCompile(`^(.*) on (.*) type`) - for _, line := range lines { - extract := mountRx.FindStringSubmatch(line) - if len(extract) > 0 { - mountPoints = append(mountPoints, []string{extract[1], extract[2]}) - } - res = strings.TrimPrefix(dir, line) - } - // Sort by size to get more restrictive mount points first - sort.Slice(mountPoints, func(i, j int) bool { - return len(mountPoints[i][0]) > len(mountPoints[j][0]) - }) - return mountPoints -} diff --git a/settings.go b/settings.go index 6042b04..496add3 100644 --- a/settings.go +++ b/settings.go @@ -50,17 +50,9 @@ func extensionsDir() (string, error) { } func windowsVarFix(input string) string { - var remoteSettingsDir = "~/.local/share/code-server/User/" - var remoteExtensionsDir = "~/.local/share/code-server/extensions/" if runtime.GOOS == "windows" { - remoteSettingsDir = ".local/share/code-server/User/" - remoteExtensionsDir = ".local/share/code-server/extensions/" + return input } - if input == "remoteSettingsDir" { - return remoteSettingsDir - } else if input == "remoteExtensionsDir" { - return remoteExtensionsDir - } - return "" + return "~/" + input } diff --git a/sshcode.go b/sshcode.go index b9ed77d..07c0d70 100644 --- a/sshcode.go +++ b/sshcode.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "log" "math/rand" "net" "net/http" @@ -10,7 +11,9 @@ import ( "os/exec" "os/signal" "path/filepath" + "regexp" "runtime" + "sort" "strconv" "strings" "syscall" @@ -107,7 +110,6 @@ func sshCode(host, dir string, o options) error { // Downloads the latest code-server and allows it to be executed. sshCmdStr := fmt.Sprintf("ssh %v %v '/usr/bin/env bash -l'", o.sshFlags, host) - sshCmd := exec.Command("sh", "-l", "-c", sshCmdStr) sshCmd.Stdout = os.Stdout sshCmd.Stderr = os.Stderr @@ -146,10 +148,9 @@ func sshCode(host, dir string, o options) error { flog.Info("Tunneling remote port %v to %v", o.remotePort, o.bindAddr) sshCmdStr := - fmt.Sprintf("ssh -tt -q -L %v:localhost:%v %v %v 'cd %v; %v --host 127.0.0.1 --auth none --port=%v'", - o.bindAddr, o.remotePort, o.sshFlags, host, dir, codeServerPath, o.remotePort, + fmt.Sprintf("ssh -tt -q -L %v:localhost:%v %v %v '%v %v --host 127.0.0.1 --auth none --port=%v'", + o.bindAddr, o.remotePort, o.sshFlags, host, codeServerPath, dir, o.remotePort, ) - // Starts code-server and forwards the remote port. sshCmd := exec.Command("sh", "-l", "-c", sshCmdStr) sshCmd.Stdin = os.Stdin @@ -341,7 +342,6 @@ func randomPort() (string, error) { // checkSSHDirectory performs sanity and safety checks on sshDirectory, and // returns a new value for o.reuseConnection depending on the checks. func checkSSHDirectory(sshDirectory string, reuseConnection bool) bool { - if runtime.GOOS == "windows" { flog.Info("OS is windows, disabling connection reuse feature") return false @@ -463,8 +463,8 @@ func syncUserSettings(sshFlags string, host string, back bool) error { return err } - //const remoteSettingsDir = ".local/share/code-server/User/" - var remoteSettingsDir = windowsVarFix("remoteSettingsDir") + var remoteSettingsDir = windowsVarFix(".local/share/code-server/User/") + var ( src = localConfDir + "/" dest = host + ":" + remoteSettingsDir @@ -489,8 +489,7 @@ func syncExtensions(sshFlags string, host string, back bool) error { return err } - //const remoteExtensionsDir = ".local/share/code-server/extensions/" - var remoteExtensionsDir = windowsVarFix("remoteExtensionsDir") + var remoteExtensionsDir = windowsVarFix(".local/share/code-server/extensions/") var ( src = localExtensionsDir + "/" @@ -561,8 +560,10 @@ chmod +x %v`, func ensureDir(path string) error { _, err := os.Stat(path) if os.IsNotExist(err) { + // This fixes a issue where GO reads `/c/` as `C:\c\` and creates + // empty directories on HOST/CLIENT that dont need to exist if runtime.GOOS == "windows" && strings.HasPrefix(path, "/c/") { - path = path[3:] + path = "C:" + path[2:] } err = os.MkdirAll(path, 0750) } @@ -624,3 +625,73 @@ func parseGCPSSHCmd(instance string) (ip, sshFlags string, err error) { return strings.TrimSpace(userIP), sshFlags, nil } + +// gitbashMountPoints returns all mount points in a msys2 system and then trunicates +// the mount point for `/` from the path provided (dir), this is done to fix an +// issue with how msys2 provides file paths to go, example. When you feed a filepath +// as user input to go, `command /opt` for example, msys2 will pass `C:\\opt` +// This causes an issue whith this program where when you run `sshcode.exe user@server /opt`, +// GO and msys2 will attempt to pass `C:\\opt` to the server. +// This function is used to prevent this. +func gitbashWindowsDir(dir string) string { + + // if dir is left empty, line82:main.go will set it to `~`, this makes it so that + // if dir is `~`, return `~/` instead of continuing with the gitbashWindowsDir() + // function. this prevens windows from trying to send a litteral instead of a relative + if dir == "~" { + return "~/" + } + + //If msys feeds a `C:` path, clense + if strings.HasPrefix(dir, "C:") { + mountPoints := gitbashMountPointsAndHome() + + // Apply mount points + absDir, _ := filepath.Abs(dir) + absDir = filepath.ToSlash(absDir) + for _, mp := range mountPoints { + if strings.HasPrefix(absDir, mp[0]) { + resolved := strings.Replace(absDir, mp[0], mp[1], 1) + + // Sometimes the resolved path can go from user input `/Workspace` + // to `//Workspace`, this if statement checks that and removes it + if strings.HasPrefix(resolved, "//") { + resolved = strings.TrimPrefix(resolved, "/") + flog.Info("Resolved windows path '%s' to '%s", dir, resolved) + return resolved + } + + flog.Info("Resolved windows path '%s' to '%s", dir, resolved) + return resolved + } + } + + } + return dir +} + +// This function returns an array with MINGW64 mount points including relative home dir +func gitbashMountPointsAndHome() [][]string { + mountPoints := [][]string{{filepath.ToSlash(os.Getenv("HOME")), "~"}} + + // Load mount points + out, err := exec.Command("mount").Output() + if err != nil { + //log.Error(err) + log.Println(err) + } + lines := strings.Split(string(out), "\n") + var mountRx = regexp.MustCompile(`^(.*) on (.*) type`) + for _, line := range lines { + extract := mountRx.FindStringSubmatch(line) + if len(extract) > 0 { + mountPoints = append(mountPoints, []string{extract[1], extract[2]}) + } + } + + // Sort by size to get more restrictive mount points first + sort.Slice(mountPoints, func(i, j int) bool { + return len(mountPoints[i][0]) > len(mountPoints[j][0]) + }) + return mountPoints +} From b8b9ab8b0d4bbc4606c79e41528877df1d625a62 Mon Sep 17 00:00:00 2001 From: Aeterne Satiatus Date: Sat, 1 Feb 2020 21:18:42 +0000 Subject: [PATCH 14/23] remove winVarFix() --- settings.go | 8 -------- sshcode.go | 12 +++++++++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/settings.go b/settings.go index 496add3..e88c260 100644 --- a/settings.go +++ b/settings.go @@ -48,11 +48,3 @@ func extensionsDir() (string, error) { } return filepath.Clean(path), nil } - -func windowsVarFix(input string) string { - if runtime.GOOS == "windows" { - return input - } - - return "~/" + input -} diff --git a/sshcode.go b/sshcode.go index a54c597..1e5265a 100644 --- a/sshcode.go +++ b/sshcode.go @@ -463,7 +463,10 @@ func syncUserSettings(sshFlags string, host string, back bool) error { return err } - var remoteSettingsDir = windowsVarFix(".local/share/code-server/User/") + var remoteSettingsDir = "~/.local/share/code-server/User/" + if runtime.GOOS == "windows" { + remoteSettingsDir = ".local/share/code-server/User/" + } var ( src = localConfDir + "/" @@ -489,8 +492,10 @@ func syncExtensions(sshFlags string, host string, back bool) error { return err } - var remoteExtensionsDir = windowsVarFix(".local/share/code-server/extensions/") - + var remoteExtensionsDir = "~/.local/share/code-server/extensions/" + if runtime.GOOS == "windows" { + remoteExtensionsDir = ".local/share/code-server/extensions/" + } var ( src = localExtensionsDir + "/" dest = host + ":" + remoteExtensionsDir @@ -517,6 +522,7 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err // locally in order to properly delete an extension. "--delete", "--copy-unsafe-links", + "-zz", src, dest, )..., ) From 67cb96dfe6a5b79dbe9e09492520519447658cf2 Mon Sep 17 00:00:00 2001 From: Merith Date: Tue, 7 Apr 2020 22:20:15 -0700 Subject: [PATCH 15/23] Simplify/rewrite directory detection. --- sshcode.go | 96 ++++++++++++++---------------------------------------- 1 file changed, 24 insertions(+), 72 deletions(-) diff --git a/sshcode.go b/sshcode.go index 1e5265a..c1897ec 100644 --- a/sshcode.go +++ b/sshcode.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "log" "math/rand" "net" "net/http" @@ -11,9 +10,7 @@ import ( "os/exec" "os/signal" "path/filepath" - "regexp" "runtime" - "sort" "strconv" "strings" "syscall" @@ -267,27 +264,28 @@ func openBrowser(url string) { const ( macPath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" - wslPath = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" - winPath = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" + wslPath = "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge_proxy.exe" + winPath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge_proxy.exe" ) switch { - case commandExists("chrome"): - openCmd = exec.Command("chrome", chromeOptions(url)...) - case commandExists("google-chrome"): - openCmd = exec.Command("google-chrome", chromeOptions(url)...) - case commandExists("google-chrome-stable"): - openCmd = exec.Command("google-chrome-stable", chromeOptions(url)...) - case commandExists("chromium"): - openCmd = exec.Command("chromium", chromeOptions(url)...) - case commandExists("chromium-browser"): - openCmd = exec.Command("chromium-browser", chromeOptions(url)...) case pathExists(macPath): openCmd = exec.Command(macPath, chromeOptions(url)...) case pathExists(wslPath): openCmd = exec.Command(wslPath, chromeOptions(url)...) case pathExists(winPath): openCmd = exec.Command(winPath, chromeOptions(url)...) + // case commandExists("chrome"): + // openCmd = exec.Command("chrome", chromeOptions(url)...) + // case commandExists("google-chrome"): + // openCmd = exec.Command("google-chrome", chromeOptions(url)...) + // case commandExists("google-chrome-stable"): + // openCmd = exec.Command("google-chrome-stable", chromeOptions(url)...) + // case commandExists("chromium"): + // openCmd = exec.Command("chromium", chromeOptions(url)...) + // case commandExists("chromium-browser"): + // openCmd = exec.Command("chromium-browser", chromeOptions(url)...) + default: err := browser.OpenURL(url) if err != nil { @@ -632,13 +630,7 @@ func parseGCPSSHCmd(instance string) (ip, sshFlags string, err error) { return strings.TrimSpace(userIP), sshFlags, nil } -// gitbashMountPoints returns all mount points in a msys2 system and then trunicates -// the mount point for `/` from the path provided (dir), this is done to fix an -// issue with how msys2 provides file paths to go, example. When you feed a filepath -// as user input to go, `command /opt` for example, msys2 will pass `C:\\opt` -// This causes an issue whith this program where when you run `sshcode.exe user@server /opt`, -// GO and msys2 will attempt to pass `C:\\opt` to the server. -// This function is used to prevent this. +// When the user passes a path such as `/Workspace`, msys2 gives sshcode `C:/msys64/Worksapce`, which is not a valid remote path func gitbashWindowsDir(dir string) string { // if dir is left empty, line82:main.go will set it to `~`, this makes it so that @@ -647,57 +639,17 @@ func gitbashWindowsDir(dir string) string { if dir == "~" { return "~/" } + mingwPrefix, _ := exec.Command("sh", "-c", "{ cd / && pwd -W; }").Output() + prefix := strings.TrimSuffix(string(mingwPrefix), "/\n") - //If msys feeds a `C:` path, clense - if strings.HasPrefix(dir, "C:") { - mountPoints := gitbashMountPointsAndHome() - - // Apply mount points - absDir, _ := filepath.Abs(dir) - absDir = filepath.ToSlash(absDir) - for _, mp := range mountPoints { - if strings.HasPrefix(absDir, mp[0]) { - resolved := strings.Replace(absDir, mp[0], mp[1], 1) - - // Sometimes the resolved path can go from user input `/Workspace` - // to `//Workspace`, this if statement checks that and removes it - if strings.HasPrefix(resolved, "//") { - resolved = strings.TrimPrefix(resolved, "/") - flog.Info("Resolved windows path '%s' to '%s", dir, resolved) - return resolved - } - - flog.Info("Resolved windows path '%s' to '%s", dir, resolved) - return resolved - } - } - + // `pwd -W` returns a new line, not good so this removes + if strings.HasPrefix(dir, prefix) { + fmt.Println(prefix + dir) + resolved := strings.TrimPrefix(dir, prefix) + fmt.Println(resolved + dir) + flog.Info("Resolved windows path '%s' to '%s", dir, resolved) + return resolved } - return dir -} - -// This function returns an array with MINGW64 mount points including relative home dir -func gitbashMountPointsAndHome() [][]string { - mountPoints := [][]string{{filepath.ToSlash(os.Getenv("HOME")), "~"}} - // Load mount points - out, err := exec.Command("mount").Output() - if err != nil { - //log.Error(err) - log.Println(err) - } - lines := strings.Split(string(out), "\n") - var mountRx = regexp.MustCompile(`^(.*) on (.*) type`) - for _, line := range lines { - extract := mountRx.FindStringSubmatch(line) - if len(extract) > 0 { - mountPoints = append(mountPoints, []string{extract[1], extract[2]}) - } - } - - // Sort by size to get more restrictive mount points first - sort.Slice(mountPoints, func(i, j int) bool { - return len(mountPoints[i][0]) > len(mountPoints[j][0]) - }) - return mountPoints + return dir } From e9c47f27de7df1b77ab7678880c78946360e5929 Mon Sep 17 00:00:00 2001 From: Merith Date: Tue, 7 Apr 2020 23:09:23 -0700 Subject: [PATCH 16/23] Revert ms-edge modifications --- sshcode.go | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/sshcode.go b/sshcode.go index c1897ec..b00eda9 100644 --- a/sshcode.go +++ b/sshcode.go @@ -264,27 +264,27 @@ func openBrowser(url string) { const ( macPath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" - wslPath = "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge_proxy.exe" - winPath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge_proxy.exe" + wslPath = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" + winPath = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" ) switch { + case commandExists("chrome"): + openCmd = exec.Command("chrome", chromeOptions(url)...) + case commandExists("google-chrome"): + openCmd = exec.Command("google-chrome", chromeOptions(url)...) + case commandExists("google-chrome-stable"): + openCmd = exec.Command("google-chrome-stable", chromeOptions(url)...) + case commandExists("chromium"): + openCmd = exec.Command("chromium", chromeOptions(url)...) + case commandExists("chromium-browser"): + openCmd = exec.Command("chromium-browser", chromeOptions(url)...) case pathExists(macPath): openCmd = exec.Command(macPath, chromeOptions(url)...) case pathExists(wslPath): openCmd = exec.Command(wslPath, chromeOptions(url)...) case pathExists(winPath): openCmd = exec.Command(winPath, chromeOptions(url)...) - // case commandExists("chrome"): - // openCmd = exec.Command("chrome", chromeOptions(url)...) - // case commandExists("google-chrome"): - // openCmd = exec.Command("google-chrome", chromeOptions(url)...) - // case commandExists("google-chrome-stable"): - // openCmd = exec.Command("google-chrome-stable", chromeOptions(url)...) - // case commandExists("chromium"): - // openCmd = exec.Command("chromium", chromeOptions(url)...) - // case commandExists("chromium-browser"): - // openCmd = exec.Command("chromium-browser", chromeOptions(url)...) default: err := browser.OpenURL(url) @@ -461,10 +461,7 @@ func syncUserSettings(sshFlags string, host string, back bool) error { return err } - var remoteSettingsDir = "~/.local/share/code-server/User/" - if runtime.GOOS == "windows" { - remoteSettingsDir = ".local/share/code-server/User/" - } + var remoteSettingsDir = windowsVarFix(".local/share/code-server/User/") var ( src = localConfDir + "/" @@ -490,10 +487,8 @@ func syncExtensions(sshFlags string, host string, back bool) error { return err } - var remoteExtensionsDir = "~/.local/share/code-server/extensions/" - if runtime.GOOS == "windows" { - remoteExtensionsDir = ".local/share/code-server/extensions/" - } + var remoteExtensionsDir = windowsVarFix(".local/share/code-server/extensions/") + var ( src = localExtensionsDir + "/" dest = host + ":" + remoteExtensionsDir @@ -520,7 +515,6 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err // locally in order to properly delete an extension. "--delete", "--copy-unsafe-links", - "-zz", src, dest, )..., ) From 836d024c73c92c921b215f6dd98c9bc41f0372f1 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-BQUQ80R\\zachd" Date: Wed, 8 Apr 2020 09:33:32 -0700 Subject: [PATCH 17/23] fix broken revert --- sshcode.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sshcode.go b/sshcode.go index b00eda9..5f11b47 100644 --- a/sshcode.go +++ b/sshcode.go @@ -461,8 +461,10 @@ func syncUserSettings(sshFlags string, host string, back bool) error { return err } - var remoteSettingsDir = windowsVarFix(".local/share/code-server/User/") - + var remoteSettingsDir = "~/.local/share/code-server/User/" + if runtime.GOOS == "windows" { + remoteSettingsDir = ".local/share/code-server/User/" + } var ( src = localConfDir + "/" dest = host + ":" + remoteSettingsDir @@ -487,7 +489,10 @@ func syncExtensions(sshFlags string, host string, back bool) error { return err } - var remoteExtensionsDir = windowsVarFix(".local/share/code-server/extensions/") + var remoteExtensionsDir = "~/.local/share/code-server/extensions/" + if runtime.GOOS == "windows" { + remoteExtensionsDir = ".local/share/code-server/extensions/" + } var ( src = localExtensionsDir + "/" @@ -515,6 +520,7 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err // locally in order to properly delete an extension. "--delete", "--copy-unsafe-links", + "-zz", src, dest, )..., ) From c2b11f4babf4f287ec862684f1dad43898c9bb15 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-BQUQ80R\\zachd" Date: Wed, 8 Apr 2020 16:10:10 -0700 Subject: [PATCH 18/23] add pr suggestions --- sshcode.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/sshcode.go b/sshcode.go index 5f11b47..aaa720c 100644 --- a/sshcode.go +++ b/sshcode.go @@ -630,26 +630,31 @@ func parseGCPSSHCmd(instance string) (ip, sshFlags string, err error) { return strings.TrimSpace(userIP), sshFlags, nil } -// When the user passes a path such as `/Workspace`, msys2 gives sshcode `C:/msys64/Worksapce`, which is not a valid remote path +// gitbashWindowsDir strips a the msys2 install directory from the beginning of +// the path. On msys2, if a user provides `/workspace` sshcode will receive +// `C:/msys64/workspace` which won't work on the remote host. func gitbashWindowsDir(dir string) string { - // if dir is left empty, line82:main.go will set it to `~`, this makes it so that - // if dir is `~`, return `~/` instead of continuing with the gitbashWindowsDir() - // function. this prevens windows from trying to send a litteral instead of a relative - if dir == "~" { - return "~/" + // Don't bother figuring out path if it's relative to home dir. + if strings.HasPrefix(dir, "~/") { + if dir == "~" { + return "~/" + } + return dir + } + + mingwPrefix, err := exec.Command("sh", "-c", "{ cd / && pwd -W; }").Output() + if err != nil { + // Default to a sane location. + mingwPrefix = []byte("C:/mingw64") } - mingwPrefix, _ := exec.Command("sh", "-c", "{ cd / && pwd -W; }").Output() + prefix := strings.TrimSuffix(string(mingwPrefix), "/\n") - // `pwd -W` returns a new line, not good so this removes if strings.HasPrefix(dir, prefix) { - fmt.Println(prefix + dir) resolved := strings.TrimPrefix(dir, prefix) - fmt.Println(resolved + dir) flog.Info("Resolved windows path '%s' to '%s", dir, resolved) return resolved } - return dir } From ad0b77273bc06e4cfbf2d7b22839f71c411a6f56 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-BQUQ80R\\zachd" Date: Wed, 8 Apr 2020 17:17:38 -0700 Subject: [PATCH 19/23] add pr suggestions --- sshcode.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sshcode.go b/sshcode.go index aaa720c..840c10b 100644 --- a/sshcode.go +++ b/sshcode.go @@ -564,8 +564,8 @@ chmod +x %v`, func ensureDir(path string) error { _, err := os.Stat(path) if os.IsNotExist(err) { - // This fixes a issue where GO reads `/c/` as `C:\c\` and creates - // empty directories on HOST/CLIENT that dont need to exist + // This fixes a issue where Go reads `/c/` as `C:\c\` and creates + // empty directories on the client that don't need to if runtime.GOOS == "windows" && strings.HasPrefix(path, "/c/") { path = "C:" + path[2:] } From 80845971ed5fa35dbc57c99ec747d4e7f38c2b8f Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Sat, 18 Apr 2020 12:28:37 -0700 Subject: [PATCH 20/23] fix typo --- sshcode.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sshcode.go b/sshcode.go index 840c10b..76b46bb 100644 --- a/sshcode.go +++ b/sshcode.go @@ -285,7 +285,6 @@ func openBrowser(url string) { openCmd = exec.Command(wslPath, chromeOptions(url)...) case pathExists(winPath): openCmd = exec.Command(winPath, chromeOptions(url)...) - default: err := browser.OpenURL(url) if err != nil { @@ -565,7 +564,7 @@ func ensureDir(path string) error { _, err := os.Stat(path) if os.IsNotExist(err) { // This fixes a issue where Go reads `/c/` as `C:\c\` and creates - // empty directories on the client that don't need to + // empty directories on the client that don't need to exist if runtime.GOOS == "windows" && strings.HasPrefix(path, "/c/") { path = "C:" + path[2:] } From 5fa66f3cda5beca743776300ba2dfcf940670c15 Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Sun, 19 Apr 2020 11:51:40 -0700 Subject: [PATCH 21/23] fix typo --- sshcode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sshcode.go b/sshcode.go index 76b46bb..6aaf3a8 100644 --- a/sshcode.go +++ b/sshcode.go @@ -564,7 +564,7 @@ func ensureDir(path string) error { _, err := os.Stat(path) if os.IsNotExist(err) { // This fixes a issue where Go reads `/c/` as `C:\c\` and creates - // empty directories on the client that don't need to exist + // empty directories on the client that don't need to exist. if runtime.GOOS == "windows" && strings.HasPrefix(path, "/c/") { path = "C:" + path[2:] } From 8e9ee5f4a4392f712e93303501486618c4f933f7 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Tue, 21 Apr 2020 09:50:33 +1000 Subject: [PATCH 22/23] Remove unnecessary log --- sshcode.go | 1 - 1 file changed, 1 deletion(-) diff --git a/sshcode.go b/sshcode.go index 6aaf3a8..3a9dda0 100644 --- a/sshcode.go +++ b/sshcode.go @@ -652,7 +652,6 @@ func gitbashWindowsDir(dir string) string { if strings.HasPrefix(dir, prefix) { resolved := strings.TrimPrefix(dir, prefix) - flog.Info("Resolved windows path '%s' to '%s", dir, resolved) return resolved } return dir From d3536bef330e2e07a3ba78bfa29c0b2c744ab253 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Tue, 21 Apr 2020 09:51:59 +1000 Subject: [PATCH 23/23] Remove unnecessary HasPrefix check --- sshcode.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sshcode.go b/sshcode.go index 3a9dda0..5021c09 100644 --- a/sshcode.go +++ b/sshcode.go @@ -649,10 +649,5 @@ func gitbashWindowsDir(dir string) string { } prefix := strings.TrimSuffix(string(mingwPrefix), "/\n") - - if strings.HasPrefix(dir, prefix) { - resolved := strings.TrimPrefix(dir, prefix) - return resolved - } - return dir + return strings.TrimPrefix(dir, prefix) }