Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit f7d230b

Browse files
author
Anthony Shull
authored
Merge pull request #14 from cdr/better-rsync-missing-error
Send stderr to ioutil.discard and log more human readable error
2 parents a02fdfe + 2b03963 commit f7d230b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

cmd/coder/sync.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"os"
56
"path/filepath"
67
"strings"
@@ -28,6 +29,9 @@ func (cmd *syncCmd) RegisterFlags(fl *pflag.FlagSet) {
2829
fl.BoolVarP(&cmd.init, "init", "i", false, "do inititial transfer and exit")
2930
}
3031

32+
// See https://lxadm.com/Rsync_exit_codes#List_of_standard_rsync_exit_codes.
33+
var NoRsync = errors.New("rsync: exit status 2")
34+
3135
func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
3236
var (
3337
local = fl.Arg(0)
@@ -49,7 +53,7 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
4953

5054
remoteTokens := strings.SplitN(remote, ":", 2)
5155
if len(remoteTokens) != 2 {
52-
flog.Fatal("remote misformmated")
56+
flog.Fatal("remote misformatted")
5357
}
5458
var (
5559
envName = remoteTokens[0]
@@ -73,5 +77,10 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
7377
for err == nil || err == sync.ErrRestartSync {
7478
err = s.Run()
7579
}
76-
flog.Fatal("sync: %v", err)
80+
81+
if err == NoRsync {
82+
flog.Fatal("no compatible rsync present on remote machine")
83+
} else {
84+
flog.Fatal("sync: %v", err)
85+
}
7786
}

internal/sync/sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"io"
8+
"io/ioutil"
89
"os"
910
"os/exec"
1011
"path"
@@ -56,7 +57,7 @@ func (s Sync) syncPaths(delete bool, local, remote string) error {
5657
// good in general for codebases.
5758
cmd := exec.Command("rsync", args...)
5859
cmd.Stdout = os.Stdout
59-
cmd.Stderr = os.Stderr
60+
cmd.Stderr = ioutil.Discard
6061
cmd.Stdin = os.Stdin
6162
err := cmd.Run()
6263
if err != nil {
@@ -248,7 +249,6 @@ func (s Sync) Run() error {
248249
return nil
249250
}
250251

251-
252252
flog.Info("watching %s for changes", s.LocalDir)
253253

254254
var droppedEvents uint64

0 commit comments

Comments
 (0)