Move Server and Key to new sub-package

This commit is contained in:
Alexander Neumann
2015-04-26 14:46:15 +02:00
parent 8498753eb7
commit d19b23d4f1
28 changed files with 317 additions and 356 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/restic/restic"
"github.com/restic/restic/backend"
"github.com/restic/restic/server"
)
type CmdCat struct{}
@@ -112,7 +113,7 @@ func (cmd CmdCat) Execute(args []string) error {
dec := json.NewDecoder(rd)
var key restic.Key
var key server.Key
err = dec.Decode(&key)
if err != nil {
return err

View File

@@ -8,6 +8,7 @@ import (
"github.com/restic/restic"
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
"github.com/restic/restic/server"
)
type findResult struct {
@@ -58,7 +59,7 @@ func parseTime(str string) (time.Time, error) {
return time.Time{}, fmt.Errorf("unable to parse time: %q", str)
}
func (c CmdFind) findInTree(s restic.Server, blob restic.Blob, path string) ([]findResult, error) {
func (c CmdFind) findInTree(s *server.Server, blob server.Blob, path string) ([]findResult, error) {
debug.Log("restic.find", "checking tree %v\n", blob)
tree, err := restic.LoadTree(s, blob)
if err != nil {
@@ -109,7 +110,7 @@ func (c CmdFind) findInTree(s restic.Server, blob restic.Blob, path string) ([]f
return results, nil
}
func (c CmdFind) findInSnapshot(s restic.Server, name string) error {
func (c CmdFind) findInSnapshot(s *server.Server, name string) error {
debug.Log("restic.find", "searching in snapshot %s\n for entries within [%s %s]", name, c.oldest, c.newest)
id, err := backend.ParseID(name)

View File

@@ -8,6 +8,7 @@ import (
"github.com/restic/restic"
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
"github.com/restic/restic/server"
)
type CmdFsck struct {
@@ -31,7 +32,7 @@ func init() {
}
}
func fsckFile(opts CmdFsck, s restic.Server, m *restic.Map, IDs []backend.ID) (uint64, error) {
func fsckFile(opts CmdFsck, s *server.Server, m *restic.Map, IDs []backend.ID) (uint64, error) {
debug.Log("restic.fsckFile", "checking file %v", IDs)
var bytes uint64
@@ -74,7 +75,7 @@ func fsckFile(opts CmdFsck, s restic.Server, m *restic.Map, IDs []backend.ID) (u
return bytes, nil
}
func fsckTree(opts CmdFsck, s restic.Server, blob restic.Blob) error {
func fsckTree(opts CmdFsck, s *server.Server, blob server.Blob) error {
debug.Log("restic.fsckTree", "checking tree %v", blob)
tree, err := restic.LoadTree(s, blob)
@@ -161,7 +162,7 @@ func fsckTree(opts CmdFsck, s restic.Server, blob restic.Blob) error {
return firstErr
}
func fsckSnapshot(opts CmdFsck, s restic.Server, id backend.ID) error {
func fsckSnapshot(opts CmdFsck, s *server.Server, id backend.ID) error {
debug.Log("restic.fsck", "checking snapshot %v\n", id)
sn, err := restic.LoadSnapshot(s, id)

View File

@@ -5,8 +5,8 @@ import (
"fmt"
"os"
"github.com/restic/restic"
"github.com/restic/restic/backend"
"github.com/restic/restic/server"
)
type CmdKey struct{}
@@ -21,7 +21,7 @@ func init() {
}
}
func listKeys(s restic.Server) error {
func listKeys(s *server.Server) error {
tab := NewTable()
tab.Header = fmt.Sprintf(" %-10s %-10s %-10s %s", "ID", "User", "Host", "Created")
tab.RowFormat = "%s%-10s %-10s %-10s %s"
@@ -35,7 +35,7 @@ func listKeys(s restic.Server) error {
defer close(done)
for name := range s.List(backend.Key, done) {
k, err := restic.LoadKey(s, name)
k, err := server.LoadKey(s, name)
if err != nil {
fmt.Fprintf(os.Stderr, "LoadKey() failed: %v\n", err)
continue
@@ -56,7 +56,7 @@ func listKeys(s restic.Server) error {
return nil
}
func addKey(s restic.Server) error {
func addKey(s *server.Server) error {
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
@@ -64,7 +64,7 @@ func addKey(s restic.Server) error {
return errors.New("passwords do not match")
}
id, err := restic.AddKey(s, pw, s.Key())
id, err := server.AddKey(s, pw, s.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
}
@@ -74,7 +74,7 @@ func addKey(s restic.Server) error {
return nil
}
func deleteKey(s restic.Server, name string) error {
func deleteKey(s *server.Server, name string) error {
if name == s.Key().Name() {
return errors.New("refusing to remove key currently used to access repository")
}
@@ -88,7 +88,7 @@ func deleteKey(s restic.Server, name string) error {
return nil
}
func changePassword(s restic.Server) error {
func changePassword(s *server.Server) error {
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
@@ -97,7 +97,7 @@ func changePassword(s restic.Server) error {
}
// add new key
id, err := restic.AddKey(s, pw, s.Key())
id, err := server.AddKey(s, pw, s.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/restic/restic"
"github.com/restic/restic/backend"
"github.com/restic/restic/server"
)
type CmdLs struct{}
@@ -37,7 +38,7 @@ func printNode(prefix string, n *restic.Node) string {
}
}
func printTree(prefix string, s restic.Server, blob restic.Blob) error {
func printTree(prefix string, s *server.Server, blob server.Blob) error {
tree, err := restic.LoadTree(s, blob)
if err != nil {
return err

View File

@@ -15,6 +15,7 @@ import (
"github.com/restic/restic/backend/local"
"github.com/restic/restic/backend/sftp"
"github.com/restic/restic/debug"
"github.com/restic/restic/server"
)
var version = "compiled manually"
@@ -72,9 +73,9 @@ func (cmd CmdInit) Execute(args []string) error {
os.Exit(1)
}
s := restic.NewServer(be)
s := server.NewServer(be)
_, err = restic.CreateKey(s, pw)
_, err = server.CreateKey(s, pw)
if err != nil {
fmt.Fprintf(os.Stderr, "creating key in backend at %s failed: %v\n", opts.Repo, err)
os.Exit(1)
@@ -134,21 +135,21 @@ func create(u string) (backend.Backend, error) {
return sftp.Create(url.Path[1:], "ssh", args...)
}
func OpenRepo() (restic.Server, error) {
func OpenRepo() (*server.Server, error) {
if opts.Repo == "" {
return restic.Server{}, errors.New("Please specify repository location (-r)")
return nil, errors.New("Please specify repository location (-r)")
}
be, err := open(opts.Repo)
if err != nil {
return restic.Server{}, err
return nil, err
}
s := restic.NewServer(be)
s := server.NewServer(be)
err = s.SearchKey(readPassword("RESTIC_PASSWORD", "enter password for repository: "))
if err != nil {
return restic.Server{}, fmt.Errorf("unable to open repo: %v", err)
return nil, fmt.Errorf("unable to open repo: %v", err)
}
return s, nil