This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Verify rsync protocol version match prior to proceeding - Rebased on current master. #71
Merged
scsmithr
merged 7 commits into
coder:master
from
stephenwithav:add-version-check-locally
Jul 2, 2020
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f745670
Verify rsync protocol version match prior to proceeding.
stephenwithav 5538af6
Add context to sync.Version.
stephenwithav 54cecb2
Correct syncCmd.version, sync.Version.
stephenwithav 35ee1de
Update local, remote version checks to avoid blanks.
stephenwithav 21976c6
Remove go from io.Copy in internal/sync/sync.go#Version
stephenwithav d853066
Return error directly in internal/sync/sync.go#Version
stephenwithav e8abef2
Update [vV]ersion comment strings; remove extraneous error check.
stephenwithav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||
package sync | ||||||
|
||||||
import ( | ||||||
"bytes" | ||||||
"context" | ||||||
"errors" | ||||||
"fmt" | ||||||
|
@@ -10,6 +11,7 @@ import ( | |||||
"os/exec" | ||||||
"path" | ||||||
"path/filepath" | ||||||
"strings" | ||||||
"sync" | ||||||
"sync/atomic" | ||||||
"time" | ||||||
|
@@ -261,6 +263,47 @@ const ( | |||||
maxAcceptableDispatch = time.Millisecond * 50 | ||||||
) | ||||||
|
||||||
// Returns remote protocol version as a string. | ||||||
// Or, an error if one exists. | ||||||
func (s Sync) Version() (string, error) { | ||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||||||
defer cancel() | ||||||
|
||||||
conn, err := s.Client.DialWsep(ctx, s.Env) | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
defer conn.Close(websocket.CloseNormalClosure, "") | ||||||
|
||||||
execer := wsep.RemoteExecer(conn) | ||||||
process, err := execer.Start(ctx, wsep.Command{ | ||||||
Command: "rsync", | ||||||
Args: []string{"--version"}, | ||||||
}) | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
buf := &bytes.Buffer{} | ||||||
io.Copy(buf, process.Stdout()) | ||||||
|
||||||
err = process.Wait() | ||||||
if code, ok := err.(wsep.ExitError); ok { | ||||||
return "", fmt.Errorf("Version check exit status: %v", code) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
if err != nil { | ||||||
return "", fmt.Errorf("Server version mismatch") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer returning the error here instead. |
||||||
} | ||||||
|
||||||
firstLine, err := buf.ReadString('\n') | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
|
||||||
versionString := strings.Split(firstLine, "protocol version ") | ||||||
|
||||||
return versionString[1], nil | ||||||
} | ||||||
|
||||||
// Run starts the sync synchronously. | ||||||
// Use this command to debug what wasn't sync'd correctly: | ||||||
// rsync -e "coder sh" -nicr ~/Projects/cdr/coder-cli/. ammar:/home/coder/coder-cli/ | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for missing this earlier in the review. These comments should start with the function/method name. So this would be "version returns local rsync protocol version as a string."
(And same for the other
Version
method)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. I appreciate you teaching me the style you prefer prior to the interview next week so if I get the job, I'm already style trained.