Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.

Commit 1b8bf23

Browse files
authored
Merge pull request #80 from cdr/multi-usr
Support multiple users using same machine
2 parents 326938c + 57ccf3a commit 1b8bf23

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

sshcode.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"golang.org/x/xerrors"
2020
)
2121

22+
const codeServerPath = "~/.cache/sshcode/sshcode-server"
23+
2224
type options struct {
2325
skipSync bool
2426
syncBack bool
@@ -30,8 +32,6 @@ type options struct {
3032
func sshCode(host, dir string, o options) error {
3133
flog.Info("ensuring code-server is updated...")
3234

33-
const codeServerPath = "/tmp/sshcode-code-server"
34-
3535
dlScript := downloadScript(codeServerPath)
3636

3737
// Downloads the latest code-server and allows it to be executed.
@@ -97,7 +97,7 @@ func sshCode(host, dir string, o options) error {
9797
sshCmd.Stderr = os.Stderr
9898
err = sshCmd.Start()
9999
if err != nil {
100-
flog.Fatal("failed to start code-server: %v", err)
100+
return xerrors.Errorf("failed to start code-server: %w", err)
101101
}
102102

103103
url := "http://127.0.0.1:" + o.localPort
@@ -313,12 +313,13 @@ func downloadScript(codeServerPath string) string {
313313
return fmt.Sprintf(
314314
`set -euxo pipefail || exit 1
315315
316-
mkdir -p ~/.local/share/code-server
316+
mkdir -p ~/.local/share/code-server %v
317317
cd %v
318318
wget -N https://codesrv-ci.cdr.sh/latest-linux
319319
[ -f %v ] && rm %v
320320
ln latest-linux %v
321321
chmod +x %v`,
322+
filepath.Dir(codeServerPath),
322323
filepath.Dir(codeServerPath),
323324
codeServerPath,
324325
codeServerPath,

sshcode_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"os/exec"
11+
"path/filepath"
1112
"strconv"
1213
"sync"
1314
"testing"
@@ -50,7 +51,11 @@ func TestSSHCode(t *testing.T) {
5051
waitForSSHCode(t, localPort, time.Second*30)
5152
waitForSSHCode(t, remotePort, time.Second*30)
5253

53-
out, err := exec.Command("pkill", "sshcode-code").CombinedOutput()
54+
// Typically we'd do an os.Stat call here but the os package doesn't expand '~'
55+
out, err := exec.Command("sh", "-c", "stat "+codeServerPath).CombinedOutput()
56+
require.NoError(t, err, "%s", out)
57+
58+
out, err = exec.Command("pkill", filepath.Base(codeServerPath)).CombinedOutput()
5459
require.NoError(t, err, "%s", out)
5560

5661
wg.Wait()

0 commit comments

Comments
 (0)