mirror of
https://github.com/zrepl/zrepl.git
synced 2025-05-31 07:09:47 +02:00
Gofmt megacommit.
This commit is contained in:
parent
9750bf3123
commit
d9ecfc8eb4
@ -1,11 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
yaml "gopkg.in/yaml.v2"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/zrepl/zrepl/zfs"
|
"github.com/zrepl/zrepl/zfs"
|
||||||
"errors"
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ func parsePools(v interface{}) (p []Pool, err error) {
|
|||||||
|
|
||||||
func parsePushs(v interface{}) (p []Push, err error) {
|
func parsePushs(v interface{}) (p []Push, err error) {
|
||||||
|
|
||||||
asList := make([]struct{
|
asList := make([]struct {
|
||||||
To string
|
To string
|
||||||
Datasets []string
|
Datasets []string
|
||||||
}, 0)
|
}, 0)
|
||||||
@ -105,12 +105,11 @@ func parsePushs(v interface{}) (p []Push, err error) {
|
|||||||
|
|
||||||
func parsePulls(v interface{}) (p []Pull, err error) {
|
func parsePulls(v interface{}) (p []Pull, err error) {
|
||||||
|
|
||||||
asList := make([]struct{
|
asList := make([]struct {
|
||||||
From string
|
From string
|
||||||
Mapping map[string]string
|
Mapping map[string]string
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
|
|
||||||
if err = mapstructure.Decode(v, &asList); err != nil {
|
if err = mapstructure.Decode(v, &asList); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -169,7 +168,7 @@ func parseComboMapping(m map[string]string) (c zfs.ComboMapping, err error) {
|
|||||||
|
|
||||||
c.Mappings = make([]zfs.DatasetMapping, len(m))
|
c.Mappings = make([]zfs.DatasetMapping, len(m))
|
||||||
|
|
||||||
for lhs,rhs := range m {
|
for lhs, rhs := range m {
|
||||||
|
|
||||||
if lhs[0] == '|' {
|
if lhs[0] == '|' {
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSampleConfigFileIsParsedWithoutErrors(t *testing.T) {
|
func TestSampleConfigFileIsParsedWithoutErrors(t *testing.T) {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"github.com/zrepl/zrepl/zfs"
|
|
||||||
"github.com/zrepl/zrepl/model"
|
"github.com/zrepl/zrepl/model"
|
||||||
"github.com/zrepl/zrepl/rpc"
|
"github.com/zrepl/zrepl/rpc"
|
||||||
|
"github.com/zrepl/zrepl/zfs"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
type Handler struct {}
|
|
||||||
|
type Handler struct{}
|
||||||
|
|
||||||
func (h Handler) HandleFilesystemRequest(r rpc.FilesystemRequest) (roots []model.Filesystem, err error) {
|
func (h Handler) HandleFilesystemRequest(r rpc.FilesystemRequest) (roots []model.Filesystem, err error) {
|
||||||
|
|
||||||
|
10
cmd/main.go
10
cmd/main.go
@ -1,12 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/urfave/cli"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"github.com/urfave/cli"
|
||||||
"github.com/zrepl/zrepl/sshbytestream"
|
|
||||||
"github.com/zrepl/zrepl/rpc"
|
"github.com/zrepl/zrepl/rpc"
|
||||||
|
"github.com/zrepl/zrepl/sshbytestream"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Role uint
|
type Role uint
|
||||||
@ -29,7 +29,7 @@ func main() {
|
|||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.StringFlag{Name: "config"},
|
cli.StringFlag{Name: "config"},
|
||||||
}
|
}
|
||||||
app.Before = func (c *cli.Context) (err error) {
|
app.Before = func(c *cli.Context) (err error) {
|
||||||
if !c.GlobalIsSet("config") {
|
if !c.GlobalIsSet("config") {
|
||||||
return errors.New("config flag not set")
|
return errors.New("config flag not set")
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ func main() {
|
|||||||
Usage: "do replication",
|
Usage: "do replication",
|
||||||
Action: doRun,
|
Action: doRun,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.RunAndExitOnError()
|
app.RunAndExitOnError()
|
||||||
|
|
||||||
|
@ -2,12 +2,11 @@ package rpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
|
||||||
|
|
||||||
. "github.com/zrepl/zrepl/model"
|
|
||||||
. "github.com/zrepl/zrepl/util"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
. "github.com/zrepl/zrepl/model"
|
||||||
|
. "github.com/zrepl/zrepl/util"
|
||||||
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"github.com/zrepl/zrepl/model"
|
"github.com/zrepl/zrepl/model"
|
||||||
"github.com/zrepl/zrepl/sshbytestream"
|
"github.com/zrepl/zrepl/sshbytestream"
|
||||||
"github.com/zrepl/zrepl/util"
|
"github.com/zrepl/zrepl/util"
|
||||||
"flag"
|
|
||||||
// "bytes"
|
// "bytes"
|
||||||
_ "bufio"
|
_ "bufio"
|
||||||
// "strings"
|
// "strings"
|
||||||
"io"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "time"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
_ "time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -45,7 +45,6 @@ func main() {
|
|||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", chunker.ChunkCount)
|
fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", chunker.ChunkCount)
|
||||||
|
|
||||||
|
|
||||||
case *mode == "outgoing":
|
case *mode == "outgoing":
|
||||||
|
|
||||||
conn, err := sshbytestream.Outgoing("client", model.SSHTransport{
|
conn, err := sshbytestream.Outgoing("client", model.SSHTransport{
|
||||||
@ -73,7 +72,6 @@ func main() {
|
|||||||
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic("unsupported mode!")
|
panic("unsupported mode!")
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package sshbytestream
|
package sshbytestream
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/zrepl/zrepl/model"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"github.com/zrepl/zrepl/model"
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"bytes"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,12 +37,12 @@ func Outgoing(name string, remote model.SSHTransport) (conn io.ReadWriteCloser,
|
|||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
sshArgs := make([]string, 0, 2 * len(remote.Options) + len(remote.TransportOpenCommand) + 4)
|
sshArgs := make([]string, 0, 2*len(remote.Options)+len(remote.TransportOpenCommand)+4)
|
||||||
sshArgs = append(sshArgs,
|
sshArgs = append(sshArgs,
|
||||||
"-p", fmt.Sprintf("%d", remote.Port),
|
"-p", fmt.Sprintf("%d", remote.Port),
|
||||||
"-o", "BatchMode=yes",
|
"-o", "BatchMode=yes",
|
||||||
)
|
)
|
||||||
for _,option := range remote.Options {
|
for _, option := range remote.Options {
|
||||||
sshArgs = append(sshArgs, "-o", option)
|
sshArgs = append(sshArgs, "-o", option)
|
||||||
}
|
}
|
||||||
sshArgs = append(sshArgs, fmt.Sprintf("%s@%s", remote.User, remote.Host))
|
sshArgs = append(sshArgs, fmt.Sprintf("%s@%s", remote.User, remote.Host))
|
||||||
@ -57,11 +57,10 @@ func Outgoing(name string, remote model.SSHTransport) (conn io.ReadWriteCloser,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if out,err = cmd.StdoutPipe(); err != nil {
|
if out, err = cmd.StdoutPipe(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
f := ForkedSSHReadWriteCloser{
|
f := ForkedSSHReadWriteCloser{
|
||||||
RemoteStdin: in,
|
RemoteStdin: in,
|
||||||
RemoteStdout: out,
|
RemoteStdout: out,
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package chunking
|
package chunking
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"encoding/binary"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ChunkBufSize uint32 = 32*1024
|
var ChunkBufSize uint32 = 32 * 1024
|
||||||
var ChunkHeaderByteOrder = binary.LittleEndian
|
var ChunkHeaderByteOrder = binary.LittleEndian
|
||||||
|
|
||||||
type Unchunker struct {
|
type Unchunker struct {
|
||||||
@ -89,7 +89,6 @@ func NewChunkerSized(conn io.Reader, chunkSize uint32) Chunker {
|
|||||||
remainingChunkBytes: 0,
|
remainingChunkBytes: 0,
|
||||||
payloadBuf: buf,
|
payloadBuf: buf,
|
||||||
headerBuf: &bytes.Buffer{},
|
headerBuf: &bytes.Buffer{},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -113,7 +112,7 @@ func (c *Chunker) Read(b []byte) (n int, err error) {
|
|||||||
|
|
||||||
// Write chunk header
|
// Write chunk header
|
||||||
c.headerBuf.Reset()
|
c.headerBuf.Reset()
|
||||||
nextChunkLen := uint32(newPayloadLen);
|
nextChunkLen := uint32(newPayloadLen)
|
||||||
headerLen := binary.Size(nextChunkLen)
|
headerLen := binary.Size(nextChunkLen)
|
||||||
err = binary.Write(c.headerBuf, ChunkHeaderByteOrder, nextChunkLen)
|
err = binary.Write(c.headerBuf, ChunkHeaderByteOrder, nextChunkLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -128,5 +127,5 @@ func (c *Chunker) Read(b []byte) (n int, err error) {
|
|||||||
n2 := copy(remainingBuf, c.payloadBuf[:c.remainingChunkBytes])
|
n2 := copy(remainingBuf, c.payloadBuf[:c.remainingChunkBytes])
|
||||||
//fmt.Printf("chunker: written: %d\n", n+int(n2))
|
//fmt.Printf("chunker: written: %d\n", n+int(n2))
|
||||||
c.remainingChunkBytes -= n2
|
c.remainingChunkBytes -= n2
|
||||||
return n+int(n2), err
|
return n + int(n2), err
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package zfs
|
package zfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"os/exec"
|
|
||||||
"io"
|
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DatasetMapping interface {
|
type DatasetMapping interface {
|
||||||
@ -26,10 +26,9 @@ func (m GlobMapping) Map(source DatasetPath) (target DatasetPath, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
target = make([]string, 0, len(source) + len(m.TargetRoot))
|
target = make([]string, 0, len(source)+len(m.TargetRoot))
|
||||||
target = append(target, m.TargetRoot...)
|
target = append(target, m.TargetRoot...)
|
||||||
|
|
||||||
|
|
||||||
for si, sc := range source {
|
for si, sc := range source {
|
||||||
target = append(target, sc)
|
target = append(target, sc)
|
||||||
if si < len(m.PrefixPath) {
|
if si < len(m.PrefixPath) {
|
||||||
@ -87,7 +86,7 @@ type ExecMapping struct {
|
|||||||
Args []string
|
Args []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExecMapping(name string, args... string) (m *ExecMapping) {
|
func NewExecMapping(name string, args ...string) (m *ExecMapping) {
|
||||||
m = &ExecMapping{
|
m = &ExecMapping{
|
||||||
Name: name,
|
Name: name,
|
||||||
Args: args,
|
Args: args,
|
||||||
@ -100,7 +99,6 @@ func (m ExecMapping) Map(source DatasetPath) (target DatasetPath, err error) {
|
|||||||
var stdin io.Writer
|
var stdin io.Writer
|
||||||
var stdout io.Reader
|
var stdout io.Reader
|
||||||
|
|
||||||
|
|
||||||
cmd := exec.Command(m.Name, m.Args...)
|
cmd := exec.Command(m.Name, m.Args...)
|
||||||
|
|
||||||
if stdin, err = cmd.StdinPipe(); err != nil {
|
if stdin, err = cmd.StdinPipe(); err != nil {
|
||||||
@ -124,7 +122,7 @@ func (m ExecMapping) Map(source DatasetPath) (target DatasetPath, err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if _, err = io.WriteString(stdin, source.ToString() + "\n"); err != nil {
|
if _, err = io.WriteString(stdin, source.ToString()+"\n"); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package zfs
|
package zfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGlobMapping(t *testing.T) {
|
func TestGlobMapping(t *testing.T) {
|
||||||
@ -40,7 +40,7 @@ func TestComboMapping(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c := ComboMapping{
|
c := ComboMapping{
|
||||||
Mappings: []DatasetMapping{m1,m2},
|
Mappings: []DatasetMapping{m1, m2},
|
||||||
}
|
}
|
||||||
|
|
||||||
var r DatasetPath
|
var r DatasetPath
|
||||||
@ -48,7 +48,7 @@ func TestComboMapping(t *testing.T) {
|
|||||||
|
|
||||||
p := toDatasetPath("a/b/q")
|
p := toDatasetPath("a/b/q")
|
||||||
|
|
||||||
r,err = m2.Map(p)
|
r, err = m2.Map(p)
|
||||||
assert.Equal(t, NoMatchError, err)
|
assert.Equal(t, NoMatchError, err)
|
||||||
|
|
||||||
r, err = c.Map(p)
|
r, err = c.Map(p)
|
||||||
|
10
zfs/zfs.go
10
zfs/zfs.go
@ -1,14 +1,14 @@
|
|||||||
package zfs
|
package zfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zrepl/zrepl/model"
|
|
||||||
"os/exec"
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"strings"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/zrepl/zrepl/model"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitialSend(snapshot string) (io.Reader, error) {
|
func InitialSend(snapshot string) (io.Reader, error) {
|
||||||
@ -103,7 +103,7 @@ func zfsList(root string, filter DatasetFilter) (datasets []DatasetPath, err err
|
|||||||
|
|
||||||
stderrOutput, err := ioutil.ReadAll(stderr)
|
stderrOutput, err := ioutil.ReadAll(stderr)
|
||||||
|
|
||||||
if waitErr:= cmd.Wait(); waitErr != nil {
|
if waitErr := cmd.Wait(); waitErr != nil {
|
||||||
err := ZFSError{
|
err := ZFSError{
|
||||||
Stderr: stderrOutput,
|
Stderr: stderrOutput,
|
||||||
WaitErr: waitErr,
|
WaitErr: waitErr,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package zfs
|
package zfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestZFSListHandlesProducesZFSErrorOnNonZeroExit(t *testing.T) {
|
func TestZFSListHandlesProducesZFSErrorOnNonZeroExit(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user