Merge pull request #178 from restic/refactor-server

Rename Server -> Repository
This commit is contained in:
Alexander Neumann
2015-05-09 22:59:02 +02:00
28 changed files with 272 additions and 272 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ import (
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
"github.com/restic/restic/pack"
"github.com/restic/restic/server"
"github.com/restic/restic/repo"
)
type CmdCat struct{}
@@ -107,7 +107,7 @@ func (cmd CmdCat) Execute(args []string) error {
dec := json.NewDecoder(rd)
var key server.Key
var key repo.Key
err = dec.Decode(&key)
if err != nil {
return err
+7 -7
View File
@@ -8,7 +8,7 @@ import (
"github.com/restic/restic"
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
"github.com/restic/restic/server"
"github.com/restic/restic/repo"
)
type findResult struct {
@@ -59,9 +59,9 @@ func parseTime(str string) (time.Time, error) {
return time.Time{}, fmt.Errorf("unable to parse time: %q", str)
}
func (c CmdFind) findInTree(s *server.Server, id backend.ID, path string) ([]findResult, error) {
func (c CmdFind) findInTree(repo *repo.Repo, id backend.ID, path string) ([]findResult, error) {
debug.Log("restic.find", "checking tree %v\n", id)
tree, err := restic.LoadTree(s, id)
tree, err := restic.LoadTree(repo, id)
if err != nil {
return nil, err
}
@@ -93,7 +93,7 @@ func (c CmdFind) findInTree(s *server.Server, id backend.ID, path string) ([]fin
}
if node.Type == "dir" {
subdirResults, err := c.findInTree(s, id, filepath.Join(path, node.Name))
subdirResults, err := c.findInTree(repo, id, filepath.Join(path, node.Name))
if err != nil {
return nil, err
}
@@ -105,7 +105,7 @@ func (c CmdFind) findInTree(s *server.Server, id backend.ID, path string) ([]fin
return results, nil
}
func (c CmdFind) findInSnapshot(s *server.Server, name string) error {
func (c CmdFind) findInSnapshot(repo *repo.Repo, 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)
@@ -113,12 +113,12 @@ func (c CmdFind) findInSnapshot(s *server.Server, name string) error {
return err
}
sn, err := restic.LoadSnapshot(s, id)
sn, err := restic.LoadSnapshot(repo, id)
if err != nil {
return err
}
results, err := c.findInTree(s, sn.Tree, "")
results, err := c.findInTree(repo, sn.Tree, "")
if err != nil {
return err
}
+12 -12
View File
@@ -10,7 +10,7 @@ import (
"github.com/restic/restic/crypto"
"github.com/restic/restic/debug"
"github.com/restic/restic/pack"
"github.com/restic/restic/server"
"github.com/restic/restic/repo"
)
type CmdFsck struct {
@@ -34,7 +34,7 @@ func init() {
}
}
func fsckFile(opts CmdFsck, s *server.Server, IDs []backend.ID) (uint64, error) {
func fsckFile(opts CmdFsck, repo *repo.Repo, IDs []backend.ID) (uint64, error) {
debug.Log("restic.fsckFile", "checking file %v", IDs)
var bytes uint64
@@ -42,7 +42,7 @@ func fsckFile(opts CmdFsck, s *server.Server, IDs []backend.ID) (uint64, error)
debug.Log("restic.fsck", " checking data blob %v\n", id)
// test if blob is in the index
packID, tpe, _, length, err := s.Index().Lookup(id)
packID, tpe, _, length, err := repo.Index().Lookup(id)
if err != nil {
return 0, fmt.Errorf("storage for blob %v (%v) not found", id, tpe)
}
@@ -52,13 +52,13 @@ func fsckFile(opts CmdFsck, s *server.Server, IDs []backend.ID) (uint64, error)
if opts.CheckData {
// load content
_, err := s.LoadBlob(pack.Data, id)
_, err := repo.LoadBlob(pack.Data, id)
if err != nil {
return 0, err
}
} else {
// test if data blob is there
ok, err := s.Test(backend.Data, packID.String())
ok, err := repo.Test(backend.Data, packID.String())
if err != nil {
return 0, err
}
@@ -77,10 +77,10 @@ func fsckFile(opts CmdFsck, s *server.Server, IDs []backend.ID) (uint64, error)
return bytes, nil
}
func fsckTree(opts CmdFsck, s *server.Server, id backend.ID) error {
func fsckTree(opts CmdFsck, repo *repo.Repo, id backend.ID) error {
debug.Log("restic.fsckTree", "checking tree %v", id.Str())
tree, err := restic.LoadTree(s, id)
tree, err := restic.LoadTree(repo, id)
if err != nil {
return err
}
@@ -122,7 +122,7 @@ func fsckTree(opts CmdFsck, s *server.Server, id backend.ID) error {
}
debug.Log("restic.fsckTree", "check file %v (%v)", node.Name, id.Str())
bytes, err := fsckFile(opts, s, node.Content)
bytes, err := fsckFile(opts, repo, node.Content)
if err != nil {
return err
}
@@ -139,7 +139,7 @@ func fsckTree(opts CmdFsck, s *server.Server, id backend.ID) error {
// record id
seenIDs.Insert(node.Subtree)
err = fsckTree(opts, s, node.Subtree)
err = fsckTree(opts, repo, node.Subtree)
if err != nil {
firstErr = err
fmt.Fprintf(os.Stderr, "%v\n", err)
@@ -157,15 +157,15 @@ func fsckTree(opts CmdFsck, s *server.Server, id backend.ID) error {
return firstErr
}
func fsckSnapshot(opts CmdFsck, s *server.Server, id backend.ID) error {
func fsckSnapshot(opts CmdFsck, repo *repo.Repo, id backend.ID) error {
debug.Log("restic.fsck", "checking snapshot %v\n", id)
sn, err := restic.LoadSnapshot(s, id)
sn, err := restic.LoadSnapshot(repo, id)
if err != nil {
return fmt.Errorf("loading snapshot %v failed: %v", id, err)
}
err = fsckTree(opts, s, sn.Tree)
err = fsckTree(opts, repo, sn.Tree)
if err != nil {
debug.Log("restic.fsck", " checking tree %v for snapshot %v\n", sn.Tree, id)
fmt.Fprintf(os.Stderr, "snapshot %v:\n error for tree %v:\n %v\n", id, sn.Tree, err)
+10 -10
View File
@@ -6,7 +6,7 @@ import (
"os"
"github.com/restic/restic/backend"
"github.com/restic/restic/server"
"github.com/restic/restic/repo"
)
type CmdKey struct{}
@@ -21,7 +21,7 @@ func init() {
}
}
func listKeys(s *server.Server) error {
func listKeys(s *repo.Repo) 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 *server.Server) error {
defer close(done)
for name := range s.List(backend.Key, done) {
k, err := server.LoadKey(s, name)
k, err := repo.LoadKey(s, name)
if err != nil {
fmt.Fprintf(os.Stderr, "LoadKey() failed: %v\n", err)
continue
@@ -56,7 +56,7 @@ func listKeys(s *server.Server) error {
return nil
}
func addKey(s *server.Server) error {
func addKey(s *repo.Repo) error {
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
@@ -64,7 +64,7 @@ func addKey(s *server.Server) error {
return errors.New("passwords do not match")
}
id, err := server.AddKey(s, pw, s.Key())
id, err := repo.AddKey(s, pw, s.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
}
@@ -74,12 +74,12 @@ func addKey(s *server.Server) error {
return nil
}
func deleteKey(s *server.Server, name string) error {
if name == s.KeyName() {
func deleteKey(repo *repo.Repo, name string) error {
if name == repo.KeyName() {
return errors.New("refusing to remove key currently used to access repository")
}
err := s.Remove(backend.Key, name)
err := repo.Remove(backend.Key, name)
if err != nil {
return err
}
@@ -88,7 +88,7 @@ func deleteKey(s *server.Server, name string) error {
return nil
}
func changePassword(s *server.Server) error {
func changePassword(s *repo.Repo) error {
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
@@ -97,7 +97,7 @@ func changePassword(s *server.Server) error {
}
// add new key
id, err := server.AddKey(s, pw, s.Key())
id, err := repo.AddKey(s, pw, s.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
}
+4 -4
View File
@@ -7,7 +7,7 @@ import (
"github.com/restic/restic"
"github.com/restic/restic/backend"
"github.com/restic/restic/server"
"github.com/restic/restic/repo"
)
type CmdLs struct{}
@@ -38,8 +38,8 @@ func printNode(prefix string, n *restic.Node) string {
}
}
func printTree(prefix string, s *server.Server, id backend.ID) error {
tree, err := restic.LoadTree(s, id)
func printTree(prefix string, repo *repo.Repo, id backend.ID) error {
tree, err := restic.LoadTree(repo, id)
if err != nil {
return err
}
@@ -48,7 +48,7 @@ func printTree(prefix string, s *server.Server, id backend.ID) error {
fmt.Println(printNode(prefix, entry))
if entry.Type == "dir" && entry.Subtree != nil {
err = printTree(filepath.Join(prefix, entry.Name), s, entry.Subtree)
err = printTree(filepath.Join(prefix, entry.Name), repo, entry.Subtree)
if err != nil {
return err
}
+4 -4
View File
@@ -14,7 +14,7 @@ import (
"github.com/restic/restic/backend/local"
"github.com/restic/restic/backend/sftp"
"github.com/restic/restic/debug"
"github.com/restic/restic/server"
"github.com/restic/restic/repo"
)
var version = "compiled manually"
@@ -72,7 +72,7 @@ func (cmd CmdInit) Execute(args []string) error {
os.Exit(1)
}
s := server.NewServer(be)
s := repo.New(be)
err = s.Init(pw)
if err != nil {
fmt.Fprintf(os.Stderr, "creating key in backend at %s failed: %v\n", opts.Repo, err)
@@ -133,7 +133,7 @@ func create(u string) (backend.Backend, error) {
return sftp.Create(url.Path[1:], "ssh", args...)
}
func OpenRepo() (*server.Server, error) {
func OpenRepo() (*repo.Repo, error) {
if opts.Repo == "" {
return nil, errors.New("Please specify repository location (-r)")
}
@@ -143,7 +143,7 @@ func OpenRepo() (*server.Server, error) {
return nil, err
}
s := server.NewServer(be)
s := repo.New(be)
err = s.SearchKey(readPassword("RESTIC_PASSWORD", "enter password for repository: "))
if err != nil {