Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Path compatibility fixes to improve WSL compatibility #211

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func loadCodeServer(ctx context.Context) (string, error) {
start := time.Now()

const cachePath = "/tmp/sail-code-server-cache/code-server"
cachePath := filepath.Join(os.TempDir(), "sail-code-server-cache/code-server")

// downloadURLPath stores the download URL, so we know whether we should update
// the binary.
Expand Down
13 changes: 6 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ func resolvePath(homedir string, path string) string {
return path
}

list := strings.Split(path, string(filepath.Separator))

for i, seg := range list {
if seg == "~" {
list[i] = homedir
}
// Replace tilde notation in path with homedir.
if path == "~" {
path = homedir
} else if strings.HasPrefix(path, "~/") {
path = filepath.Join(homedir, path[2:])
}

return filepath.Join(list...)
return filepath.Clean(path)
}

// config describes the config.toml.
Expand Down
7 changes: 3 additions & 4 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
// Mount in VS Code configs.
mounts = append(mounts, mount.Mount{
Type: "bind",
Source: "~/.config/Code",
Source: vscodeConfigDir(),
Target: "~/.config/Code",
})
mounts = append(mounts, mount.Mount{
Type: "bind",
Source: "~/.vscode/extensions",
Source: vscodeExtensionsDir(),
Target: hostExtensionsDir,
})

Expand All @@ -251,8 +251,7 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
// socket to the container allows for using the user's existing setup for
// ssh authentication instead of having to create a new keys or explicity
// pass them in.
sshAuthSock, exists := os.LookupEnv("SSH_AUTH_SOCK")
if exists {
if sshAuthSock, exists := os.LookupEnv("SSH_AUTH_SOCK"); exists {
mounts = append(mounts, mount.Mount{
Type: "bind",
Source: sshAuthSock,
Expand Down
33 changes: 33 additions & 0 deletions vscode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"os"
"path/filepath"
"runtime"
)

const (
vsCodeConfigDirEnv = "VSCODE_CONFIG_DIR"
vsCodeExtensionsDirEnv = "VSCODE_EXTENSIONS_DIR"
)

func vscodeConfigDir() string {
if env, ok := os.LookupEnv(vsCodeConfigDirEnv); ok {
return os.ExpandEnv(env)
}

path := os.ExpandEnv("$HOME/.config/Code/")
if runtime.GOOS == "darwin" {
path = os.ExpandEnv("$HOME/Library/Application Support/Code/")
}
return filepath.Clean(path)
}

func vscodeExtensionsDir() string {
if env, ok := os.LookupEnv(vsCodeExtensionsDirEnv); ok {
return os.ExpandEnv(env)
}

path := os.ExpandEnv("$HOME/.vscode/extensions/")
return filepath.Clean(path)
}