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

Support multiple users using same machine #80

Merged
merged 1 commit into from
Apr 30, 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
9 changes: 5 additions & 4 deletions sshcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"golang.org/x/xerrors"
)

const codeServerPath = "~/.cache/sshcode/sshcode-server"

type options struct {
skipSync bool
syncBack bool
Expand All @@ -30,8 +32,6 @@ type options struct {
func sshCode(host, dir string, o options) error {
flog.Info("ensuring code-server is updated...")

const codeServerPath = "/tmp/sshcode-code-server"

dlScript := downloadScript(codeServerPath)

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

url := "http://127.0.0.1:" + o.localPort
Expand Down Expand Up @@ -313,12 +313,13 @@ func downloadScript(codeServerPath string) string {
return fmt.Sprintf(
`set -euxo pipefail || exit 1

mkdir -p ~/.local/share/code-server
mkdir -p ~/.local/share/code-server %v
cd %v
wget -N https://codesrv-ci.cdr.sh/latest-linux
[ -f %v ] && rm %v
ln latest-linux %v
chmod +x %v`,
filepath.Dir(codeServerPath),
filepath.Dir(codeServerPath),
codeServerPath,
codeServerPath,
Expand Down
7 changes: 6 additions & 1 deletion sshcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"strconv"
"sync"
"testing"
Expand Down Expand Up @@ -50,7 +51,11 @@ func TestSSHCode(t *testing.T) {
waitForSSHCode(t, localPort, time.Second*30)
waitForSSHCode(t, remotePort, time.Second*30)

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

out, err = exec.Command("pkill", filepath.Base(codeServerPath)).CombinedOutput()
require.NoError(t, err, "%s", out)

wg.Wait()
Expand Down