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

Commit

Permalink
path compatibility fixes to improve WSL compat. (#211)
Browse files Browse the repository at this point in the history
- Add `VSCODE_CONFIG_DIR` and `VSCODE_EXTENSIONS_DIR` environment
  variables to change the bind mounted code-server and config and
  extensions directories
- Change the default bind mounted code-server config and extension
  paths on darwin
- Change the code-server cache path to use os.TempDir() instead of
  hard-coded /tmp
- Change the resolvePath() function to be compatible with shells
  • Loading branch information
deansheather authored and Nathan Potter committed Jun 11, 2019
1 parent e0da2f8 commit 8195b9e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
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)
}

0 comments on commit 8195b9e

Please sign in to comment.