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

Verify rsync protocol version match prior to proceeding - Rebased on current master. #71

Merged
merged 7 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
stephenwithav committed Jul 2, 2020
commit 54cecb24a578b30de0ce04fb6d906723bd01ef62
11 changes: 8 additions & 3 deletions cmd/coder/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ func (s *syncCmd) version() string {
log.Fatal(err)
}

versionString := strings.Split(r.ReadLine(), "protocol version ")
firstLine, err := r.ReadString('\n')
if err != nil {
return ""
}

versionString := strings.Split(firstLine, "protocol version ")

return versionString[1]
}
Expand Down Expand Up @@ -103,8 +108,8 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
Client: entClient,
}

localVersion := s.version()
remoteVersion, rsyncErr := sync.Version()
localVersion := cmd.version()
remoteVersion, rsyncErr := s.Version()

if rsyncErr != nil {
flog.Info("Unable to determine remote rsync version. Proceeding cautiously.")
Expand Down
9 changes: 7 additions & 2 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,18 @@ func (s Sync) Version() (string, error) {

err = process.Wait()
if code, ok := err.(wsep.ExitError); ok {
return "", err
return "", fmt.Errorf("Version heck exit status: %v", code)
}
if err != nil {
return "", fmt.Errorf("Server version mismatch")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer returning the error here instead.

}

firstLine, err := r.ReadString('\n')
if err != nil {
return "", err
}

versionString := strings.Split(r.ReadLine(), "protocol version ")
versionString := strings.Split(firstLine, "protocol version ")

return versionString[1], nil
}
Expand Down