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

Commit 8195b9e

Browse files
deansheatherNathan Potter
authored and
Nathan Potter
committed
path compatibility fixes to improve WSL compat. (#211)
- 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
1 parent e0da2f8 commit 8195b9e

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

codeserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
func loadCodeServer(ctx context.Context) (string, error) {
2525
start := time.Now()
2626

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

2929
// downloadURLPath stores the download URL, so we know whether we should update
3030
// the binary.

config.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ func resolvePath(homedir string, path string) string {
1818
return path
1919
}
2020

21-
list := strings.Split(path, string(filepath.Separator))
22-
23-
for i, seg := range list {
24-
if seg == "~" {
25-
list[i] = homedir
26-
}
21+
// Replace tilde notation in path with homedir.
22+
if path == "~" {
23+
path = homedir
24+
} else if strings.HasPrefix(path, "~/") {
25+
path = filepath.Join(homedir, path[2:])
2726
}
2827

29-
return filepath.Join(list...)
28+
return filepath.Clean(path)
3029
}
3130

3231
// config describes the config.toml.

runner.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
236236
// Mount in VS Code configs.
237237
mounts = append(mounts, mount.Mount{
238238
Type: "bind",
239-
Source: "~/.config/Code",
239+
Source: vscodeConfigDir(),
240240
Target: "~/.config/Code",
241241
})
242242
mounts = append(mounts, mount.Mount{
243243
Type: "bind",
244-
Source: "~/.vscode/extensions",
244+
Source: vscodeExtensionsDir(),
245245
Target: hostExtensionsDir,
246246
})
247247

@@ -251,8 +251,7 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
251251
// socket to the container allows for using the user's existing setup for
252252
// ssh authentication instead of having to create a new keys or explicity
253253
// pass them in.
254-
sshAuthSock, exists := os.LookupEnv("SSH_AUTH_SOCK")
255-
if exists {
254+
if sshAuthSock, exists := os.LookupEnv("SSH_AUTH_SOCK"); exists {
256255
mounts = append(mounts, mount.Mount{
257256
Type: "bind",
258257
Source: sshAuthSock,

vscode.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"runtime"
7+
)
8+
9+
const (
10+
vsCodeConfigDirEnv = "VSCODE_CONFIG_DIR"
11+
vsCodeExtensionsDirEnv = "VSCODE_EXTENSIONS_DIR"
12+
)
13+
14+
func vscodeConfigDir() string {
15+
if env, ok := os.LookupEnv(vsCodeConfigDirEnv); ok {
16+
return os.ExpandEnv(env)
17+
}
18+
19+
path := os.ExpandEnv("$HOME/.config/Code/")
20+
if runtime.GOOS == "darwin" {
21+
path = os.ExpandEnv("$HOME/Library/Application Support/Code/")
22+
}
23+
return filepath.Clean(path)
24+
}
25+
26+
func vscodeExtensionsDir() string {
27+
if env, ok := os.LookupEnv(vsCodeExtensionsDirEnv); ok {
28+
return os.ExpandEnv(env)
29+
}
30+
31+
path := os.ExpandEnv("$HOME/.vscode/extensions/")
32+
return filepath.Clean(path)
33+
}

0 commit comments

Comments
 (0)