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

Commit 35ee1de

Browse files
committed
Update local, remote version checks to avoid blanks.
1 parent 54cecb2 commit 35ee1de

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

cmd/coder/sync.go

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

33
import (
4-
"bufio"
5-
"errors"
4+
"bytes"
65
"fmt"
76
"log"
87
"os"
@@ -34,32 +33,18 @@ func (cmd *syncCmd) RegisterFlags(fl *pflag.FlagSet) {
3433
fl.BoolVarP(&cmd.init, "init", "i", false, "do initial transfer and exit")
3534
}
3635

37-
// See https://lxadm.com/Rsync_exit_codes#List_of_standard_rsync_exit_codes.
38-
var IncompatRsync = errors.New("rsync: exit status 2")
39-
var StreamErrRsync = errors.New("rsync: exit status 12")
40-
4136
// Returns local rsync protocol version as a string.
42-
func (s *syncCmd) version() string {
37+
func (_ *syncCmd) version() string {
4338
cmd := exec.Command("rsync", "--version")
44-
stdout, err := cmd.StdoutPipe()
39+
out, err := cmd.CombinedOutput()
4540
if err != nil {
4641
log.Fatal(err)
4742
}
4843

49-
if err := cmd.Start(); err != nil {
50-
log.Fatal(err)
51-
}
52-
53-
r := bufio.NewReader(stdout)
54-
if err := cmd.Wait(); err != nil {
55-
log.Fatal(err)
56-
}
57-
58-
firstLine, err := r.ReadString('\n')
44+
firstLine, err := bytes.NewBuffer(out).ReadString('\n')
5945
if err != nil {
60-
return ""
46+
log.Fatal(err)
6147
}
62-
6348
versionString := strings.Split(firstLine, "protocol version ")
6449

6550
return versionString[1]

internal/sync/sync.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package sync
22

33
import (
4-
"bufio"
4+
"bytes"
55
"context"
66
"errors"
77
"fmt"
@@ -283,7 +283,8 @@ func (s Sync) Version() (string, error) {
283283
if err != nil {
284284
return "", err
285285
}
286-
r := bufio.NewReader(process.Stdout())
286+
buf := &bytes.Buffer{}
287+
go io.Copy(buf, process.Stdout())
287288

288289
err = process.Wait()
289290
if code, ok := err.(wsep.ExitError); ok {
@@ -293,7 +294,7 @@ func (s Sync) Version() (string, error) {
293294
return "", fmt.Errorf("Server version mismatch")
294295
}
295296

296-
firstLine, err := r.ReadString('\n')
297+
firstLine, err := buf.ReadString('\n')
297298
if err != nil {
298299
return "", err
299300
}

0 commit comments

Comments
 (0)