◐ Shell
reader mode source ↗
Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.
Merged
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
53 changes: 28 additions & 25 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"time"

"github.com/pkg/browser"
Expand Down Expand Up @@ -58,41 +59,42 @@ More info: https://github.com/codercom/sshcode

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

// Downloads the latest code-server and allows it to be executed.
sshCmd := exec.Command("ssh",
"-tt",
host,
`/bin/bash -c 'set -euxo pipefail || exit 1
# Make sure any currently running code-server is gone so we can overwrite
# the binary.
pkill -9 `+filepath.Base(codeServerPath)+` || true
wget -q https://codesrv-ci.cdr.sh/latest-linux -O `+codeServerPath+`
mkdir -p ~/.local/share/code-server
cd `+filepath.Dir(codeServerPath)+`
wget -N https://codesrv-ci.cdr.sh/latest-linux
[ -f `+codeServerPath+` ] && rm `+codeServerPath+`
ln latest-linux `+codeServerPath+`
chmod +x `+codeServerPath+`
'`,
)
sshCmd.Stdout = os.Stdout
sshCmd.Stderr = os.Stderr
err := sshCmd.Run()
if err != nil {
flog.Fatal("failed to update code-server: %v", err)
}

if !*skipSyncFlag {
start := time.Now()
flog.Info("syncing settings")
err = syncUserSettings(host, false)
if err != nil {
flog.Fatal("failed to sync settings: %v", err)
}
flog.Info("synced settings in %s", time.Since(start))

flog.Info("syncing extensions")
err = syncExtensions(host, false)
if err != nil {
flog.Fatal("failed to sync extensions: %v", err)
}
@@ -105,7 +107,7 @@ chmod +x `+codeServerPath+`
flog.Fatal("failed to find available port: %v", err)
}

sshCmdStr := fmt.Sprintf("ssh -tt -q -L %v %v %v 'cd %v; %v --host 127.0.0.1 --allow-http --no-auth --port=%v'",
localPort+":localhost:"+localPort, *sshFlags, host, dir, codeServerPath, localPort,
)

Expand Up @@ -162,12 +164,12 @@ chmod +x `+codeServerPath+`

flog.Info("synchronizing VS Code back to local")

err = syncExtensions(host, true)
if err != nil {
flog.Fatal("failed to sync extensions back: %v", err)
}

err = syncUserSettings(host, true)
if err != nil {
flog.Fatal("failed to user settigns extensions back: %v", err)
}
Expand Down Expand Up @@ -235,7 +237,7 @@ func randomPort() (string, error) {
return "", xerrors.Errorf("max number of tries exceeded: %d", maxTries)
}

func syncUserSettings(host string, back bool) error {
localConfDir, err := configDir()
if err != nil {
return err
Expand All @@ -252,10 +254,10 @@ func syncUserSettings(host string, back bool) error {
}

// Append "/" to have rsync copy the contents of the dir.
return rsync(src, dest, "workspaceStorage", "logs", "CachedData")
}

func syncExtensions(host string, back bool) error {
localExtensionsDir, err := extensionsDir()
if err != nil {
return err
Expand All @@ -270,16 +272,17 @@ func syncExtensions(host string, back bool) error {
dest, src = src, dest
}

return rsync(src, dest)
}

func rsync(src string, dest string, excludePaths ...string) error {
excludeFlags := make([]string, len(excludePaths))
for i, path := range excludePaths {
excludeFlags[i] = "--exclude=" + path
}

cmd := exec.Command("rsync", append(excludeFlags, "-azvr",
// Only update newer directories, and sync times
// to keep things simple.
"-u", "--times",
Expand Down
Toggle all file notes Toggle all file annotations