Skip to content

Commit

Permalink
Made build work again, partially refactored controller/agent.
Browse files Browse the repository at this point in the history
This commit adds some one-shot rsync functions that can be used until we
can get the endpoint refactored to re-use rsync engines.

It also removes our multiplexing package - this is probably not the
right way to go.

Finally, it adds a few cleanups to agent and controller code, but much
more awaits.
  • Loading branch information
xenoscopic committed Apr 7, 2017
1 parent fe9328a commit 6c1a47c
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 867 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ install:
# go test -v -race -cover ./...
script:
- go version
- go test -v -race -cover github.com/havoc-io/mutagen/multiplex
- go test -v -race -cover github.com/havoc-io/mutagen/rsync
- go test -v -race -cover github.com/havoc-io/mutagen/sync
- go test -v -race -cover github.com/havoc-io/mutagen/url
Expand Down
2 changes: 1 addition & 1 deletion agent/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func connectSSH(remote *url.URL, prompter, mode string) (io.ReadWriteCloser, boo
}

// Create a stream that wrap's the process' standard input/output.
stream, err := newProcessStream(process)
stream, err := newAgentStream(process)
if err != nil {
return nil, false, errors.Wrap(err, "unable to create SSH process stream")
}
Expand Down
38 changes: 27 additions & 11 deletions agent/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@ import (
"os/exec"

"github.com/pkg/errors"

"github.com/havoc-io/mutagen/stream"
)

// processStream implements io.ReadWriteCloser around the standard input/output
// of a process.
type processStream struct {
// agentStream implements io.ReadWriteCloser around the standard input/output of
// an agent process.
type agentStream struct {
process *exec.Cmd
io.ReadWriteCloser
io.Reader
io.Writer
}

// Close closes the agent stream.
// HACK: Rather than closing the process' standard input/output, this method
// simply terminates the agent process. The problem with closing the
// input/output streams is that they'll be OS pipes that might be blocked in
// reads or writes and won't necessarily unblock if closed, and they might even
// block the close - it's all platform dependent. But terminating the process
// will close the remote ends of the pipes and thus unblocks and reads/writes.
func (s *agentStream) Close() error {
// HACK: Accessing the Process field of an os/exec.Cmd could be a bit
// dangerous if other code was accessing the Cmd at the same time, but in
// our case the Cmd becomes completely encapsulated inside agentStream
// before agentStream is returned, so it's okay.
if s.process.Process != nil {
if err := s.process.Process.Kill(); err != nil {
return errors.Wrap(err, "unable to kill underlying process")
}
}
return nil
}

func newProcessStream(process *exec.Cmd) (io.ReadWriteCloser, error) {
func newAgentStream(process *exec.Cmd) (io.ReadWriteCloser, error) {
// Redirect the process' standard input.
standardInput, err := process.StdinPipe()
if err != nil {
Expand All @@ -30,8 +49,5 @@ func newProcessStream(process *exec.Cmd) (io.ReadWriteCloser, error) {
}

// Create the result.
return &processStream{
process,
stream.New(standardOutput, standardInput, standardInput),
}, nil
return &agentStream{process, standardOutput, standardInput}, nil
}
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ before_test:
# go test -v %RACEFLAG% -cover ./...
test_script:
- go version
- go test -v %RACEFLAG% -cover github.com/havoc-io/mutagen/multiplex
- go test -v %RACEFLAG% -cover github.com/havoc-io/mutagen/rsync
- go test -v %RACEFLAG% -cover github.com/havoc-io/mutagen/sync
- go test -v %RACEFLAG% -cover github.com/havoc-io/mutagen/url
Expand Down
17 changes: 15 additions & 2 deletions cmd/mutagen-agent/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"io"
"os"
"os/signal"

Expand All @@ -10,12 +11,24 @@ import (
"github.com/havoc-io/mutagen/agent"
"github.com/havoc-io/mutagen/cmd"
"github.com/havoc-io/mutagen/session"
"github.com/havoc-io/mutagen/stream"
)

var agentUsage = `usage: mutagen-agent should not be manually invoked
`

type stdio struct {
io.Reader
io.Writer
}

func (s *stdio) Close() error {
// HACK: We can't really close standard input/output pipes because doing so
// won't necessarily unblock and reads/writes and might also block the
// close. Fortunately, we don't need to support this in the agent - the
// streams should have the same lifetime as the process.
panic("standard input/output closed in agent")
}

func main() {
// Parse flags.
flagSet := cmd.NewFlagSet("mutagen-agent", agentUsage, []int{1})
Expand All @@ -33,7 +46,7 @@ func main() {
agent.Housekeep()

// Create a stream on standard input/output.
stdio := stream.New(os.Stdin, os.Stdout, os.Stdout)
stdio := &stdio{os.Stdin, os.Stdout}

// Perform a handshake.
if err := mutagen.SendVersion(stdio); err != nil {
Expand Down
82 changes: 0 additions & 82 deletions multiplex/copy.go

This file was deleted.

68 changes: 0 additions & 68 deletions multiplex/header.go

This file was deleted.

47 changes: 0 additions & 47 deletions multiplex/header_test.go

This file was deleted.

Loading

0 comments on commit 6c1a47c

Please sign in to comment.