From f2a920d6396f93d925891a74ae377e627f6cf2a6 Mon Sep 17 00:00:00 2001 From: Anthony Shull Date: Tue, 12 May 2020 11:46:05 -0500 Subject: [PATCH 1/2] Send stderr to ioutil.discard and log more human readable error --- cmd/coder/sync.go | 12 ++++++++++-- internal/sync/sync.go | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/coder/sync.go b/cmd/coder/sync.go index b28afd08..2e4dfa4e 100644 --- a/cmd/coder/sync.go +++ b/cmd/coder/sync.go @@ -1,6 +1,7 @@ package main import ( + "errors" "os" "path/filepath" "strings" @@ -28,6 +29,8 @@ func (cmd *syncCmd) RegisterFlags(fl *pflag.FlagSet) { fl.BoolVarP(&cmd.init, "init", "i", false, "do inititial transfer and exit") } +var NoRsync = errors.New("rsync: exit status 2") + func (cmd *syncCmd) Run(fl *pflag.FlagSet) { var ( local = fl.Arg(0) @@ -49,7 +52,7 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) { remoteTokens := strings.SplitN(remote, ":", 2) if len(remoteTokens) != 2 { - flog.Fatal("remote misformmated") + flog.Fatal("remote misformatted") } var ( envName = remoteTokens[0] @@ -73,5 +76,10 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) { for err == nil || err == sync.ErrRestartSync { err = s.Run() } - flog.Fatal("sync: %v", err) + + if err == NoRsync { + flog.Fatal("no compatible rsync present on remote machine") + } else { + flog.Fatal("sync: %v", err) + } } diff --git a/internal/sync/sync.go b/internal/sync/sync.go index 5c695260..2696ba1c 100644 --- a/internal/sync/sync.go +++ b/internal/sync/sync.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "io/ioutil" "os" "os/exec" "path" @@ -56,7 +57,7 @@ func (s Sync) syncPaths(delete bool, local, remote string) error { // good in general for codebases. cmd := exec.Command("rsync", args...) cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + cmd.Stderr = ioutil.Discard cmd.Stdin = os.Stdin err := cmd.Run() if err != nil { @@ -248,7 +249,6 @@ func (s Sync) Run() error { return nil } - flog.Info("watching %s for changes", s.LocalDir) var droppedEvents uint64 From 2b03963176ae820b6f3574a512b835554da39d69 Mon Sep 17 00:00:00 2001 From: Anthony Shull Date: Tue, 12 May 2020 11:58:27 -0500 Subject: [PATCH 2/2] Update cmd/coder/sync.go Co-authored-by: Ammar Bandukwala --- cmd/coder/sync.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/coder/sync.go b/cmd/coder/sync.go index 2e4dfa4e..d5b4d4bb 100644 --- a/cmd/coder/sync.go +++ b/cmd/coder/sync.go @@ -29,6 +29,7 @@ func (cmd *syncCmd) RegisterFlags(fl *pflag.FlagSet) { fl.BoolVarP(&cmd.init, "init", "i", false, "do inititial transfer and exit") } +// See https://lxadm.com/Rsync_exit_codes#List_of_standard_rsync_exit_codes. var NoRsync = errors.New("rsync: exit status 2") func (cmd *syncCmd) Run(fl *pflag.FlagSet) {