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

Commit 54cecb2

Browse files
committed
Correct syncCmd.version, sync.Version.
Passing `s.ReadLine` to `strings.Split` was a mistake since it returns three values. Having access to `wsep` helped the compiler find the bugs.
1 parent 5538af6 commit 54cecb2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cmd/coder/sync.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ func (s *syncCmd) version() string {
5555
log.Fatal(err)
5656
}
5757

58-
versionString := strings.Split(r.ReadLine(), "protocol version ")
58+
firstLine, err := r.ReadString('\n')
59+
if err != nil {
60+
return ""
61+
}
62+
63+
versionString := strings.Split(firstLine, "protocol version ")
5964

6065
return versionString[1]
6166
}
@@ -103,8 +108,8 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
103108
Client: entClient,
104109
}
105110

106-
localVersion := s.version()
107-
remoteVersion, rsyncErr := sync.Version()
111+
localVersion := cmd.version()
112+
remoteVersion, rsyncErr := s.Version()
108113

109114
if rsyncErr != nil {
110115
flog.Info("Unable to determine remote rsync version. Proceeding cautiously.")

internal/sync/sync.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,18 @@ func (s Sync) Version() (string, error) {
287287

288288
err = process.Wait()
289289
if code, ok := err.(wsep.ExitError); ok {
290-
return "", err
290+
return "", fmt.Errorf("Version heck exit status: %v", code)
291+
}
292+
if err != nil {
293+
return "", fmt.Errorf("Server version mismatch")
291294
}
295+
296+
firstLine, err := r.ReadString('\n')
292297
if err != nil {
293298
return "", err
294299
}
295300

296-
versionString := strings.Split(r.ReadLine(), "protocol version ")
301+
versionString := strings.Split(firstLine, "protocol version ")
297302

298303
return versionString[1], nil
299304
}

0 commit comments

Comments
 (0)