From 8be9e95d20db5c4c7fac31a726b13de0d4715268 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 9 May 2015 13:21:28 +0200 Subject: [PATCH] Rename package 'server' to 'repo' --- archiver.go | 6 +++--- cache.go | 6 +++--- cmd/restic/cmd_cat.go | 4 ++-- cmd/restic/cmd_find.go | 6 +++--- cmd/restic/cmd_fsck.go | 8 ++++---- cmd/restic/cmd_key.go | 16 ++++++++-------- cmd/restic/cmd_ls.go | 4 ++-- cmd/restic/main.go | 8 ++++---- node.go | 8 ++++---- {server => repo}/blob.go | 2 +- repo/doc.go | 2 ++ {server => repo}/index.go | 2 +- {server => repo}/index_test.go | 14 +++++++------- {server => repo}/key.go | 2 +- {server => repo}/pool.go | 2 +- {server => repo}/server.go | 2 +- {server => repo}/server_test.go | 2 +- restorer.go | 6 +++--- server/doc.go | 2 -- snapshot.go | 4 ++-- test/backend.go | 10 +++++----- tree.go | 4 ++-- walk.go | 6 +++--- 23 files changed, 63 insertions(+), 63 deletions(-) rename {server => repo}/blob.go (98%) create mode 100644 repo/doc.go rename {server => repo}/index.go (99%) rename {server => repo}/index_test.go (95%) rename {server => repo}/key.go (99%) rename {server => repo}/pool.go (94%) rename {server => repo}/server.go (99%) rename {server => repo}/server_test.go (99%) delete mode 100644 server/doc.go diff --git a/archiver.go b/archiver.go index cc5d079b1..76108921a 100644 --- a/archiver.go +++ b/archiver.go @@ -15,7 +15,7 @@ import ( "github.com/restic/restic/debug" "github.com/restic/restic/pack" "github.com/restic/restic/pipe" - "github.com/restic/restic/server" + "github.com/restic/restic/repo" "github.com/juju/errors" ) @@ -30,7 +30,7 @@ var archiverAllowAllFiles = func(string, os.FileInfo) bool { return true } // Archiver is used to backup a set of directories. type Archiver struct { - s *server.Server + s *repo.Server blobToken chan struct{} @@ -39,7 +39,7 @@ type Archiver struct { } // NewArchiver returns a new archiver. -func NewArchiver(s *server.Server) *Archiver { +func NewArchiver(s *repo.Server) *Archiver { arch := &Archiver{ s: s, blobToken: make(chan struct{}, maxConcurrentBlobs), diff --git a/cache.go b/cache.go index a3c7b8953..83321a363 100644 --- a/cache.go +++ b/cache.go @@ -10,7 +10,7 @@ import ( "github.com/restic/restic/backend" "github.com/restic/restic/debug" - "github.com/restic/restic/server" + "github.com/restic/restic/repo" ) // Cache is used to locally cache items from a server. @@ -18,7 +18,7 @@ type Cache struct { base string } -func NewCache(s *server.Server) (*Cache, error) { +func NewCache(s *repo.Server) (*Cache, error) { cacheDir, err := getCacheDir() if err != nil { return nil, err @@ -106,7 +106,7 @@ func (c *Cache) purge(t backend.Type, subtype string, id backend.ID) error { } // Clear removes information from the cache that isn't present in the server any more. -func (c *Cache) Clear(s *server.Server) error { +func (c *Cache) Clear(s *repo.Server) error { list, err := c.list(backend.Snapshot) if err != nil { return err diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 8fa54ed27..b90d85d45 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -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 diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 077752001..43f0c45da 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -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,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 *server.Server, id backend.ID, path string) ([]findResult, error) { +func (c CmdFind) findInTree(s *repo.Server, id backend.ID, path string) ([]findResult, error) { debug.Log("restic.find", "checking tree %v\n", id) tree, err := restic.LoadTree(s, id) if err != nil { @@ -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(s *repo.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) diff --git a/cmd/restic/cmd_fsck.go b/cmd/restic/cmd_fsck.go index eac4c4030..714753014 100644 --- a/cmd/restic/cmd_fsck.go +++ b/cmd/restic/cmd_fsck.go @@ -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, s *repo.Server, IDs []backend.ID) (uint64, error) { debug.Log("restic.fsckFile", "checking file %v", IDs) var bytes uint64 @@ -77,7 +77,7 @@ 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, s *repo.Server, id backend.ID) error { debug.Log("restic.fsckTree", "checking tree %v", id.Str()) tree, err := restic.LoadTree(s, id) @@ -157,7 +157,7 @@ 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, s *repo.Server, id backend.ID) error { debug.Log("restic.fsck", "checking snapshot %v\n", id) sn, err := restic.LoadSnapshot(s, id) diff --git a/cmd/restic/cmd_key.go b/cmd/restic/cmd_key.go index de58d50cb..1fbccc084 100644 --- a/cmd/restic/cmd_key.go +++ b/cmd/restic/cmd_key.go @@ -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.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 *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.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 *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,7 +74,7 @@ func addKey(s *server.Server) error { return nil } -func deleteKey(s *server.Server, name string) error { +func deleteKey(s *repo.Server, name string) error { if name == s.KeyName() { return errors.New("refusing to remove key currently used to access repository") } @@ -88,7 +88,7 @@ func deleteKey(s *server.Server, name string) error { return nil } -func changePassword(s *server.Server) error { +func changePassword(s *repo.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 *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) } diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index b65a02eb1..d31aaaf8c 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -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,7 +38,7 @@ func printNode(prefix string, n *restic.Node) string { } } -func printTree(prefix string, s *server.Server, id backend.ID) error { +func printTree(prefix string, s *repo.Server, id backend.ID) error { tree, err := restic.LoadTree(s, id) if err != nil { return err diff --git a/cmd/restic/main.go b/cmd/restic/main.go index 8b552ae26..d87f6aeec 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -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.NewServer(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.Server, 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.NewServer(be) err = s.SearchKey(readPassword("RESTIC_PASSWORD", "enter password for repository: ")) if err != nil { diff --git a/node.go b/node.go index c39bc4941..023ce4463 100644 --- a/node.go +++ b/node.go @@ -14,7 +14,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" ) // Node is a file, directory or other item in a backup. @@ -43,7 +43,7 @@ type Node struct { path string err error - blobs server.Blobs + blobs repo.Blobs } func (node Node) String() string { @@ -103,7 +103,7 @@ func nodeTypeFromFileInfo(fi os.FileInfo) string { } // CreateAt creates the node at the given path and restores all the meta data. -func (node *Node) CreateAt(path string, s *server.Server) error { +func (node *Node) CreateAt(path string, s *repo.Server) error { switch node.Type { case "dir": if err := node.createDirAt(path); err != nil { @@ -176,7 +176,7 @@ func (node Node) createDirAt(path string) error { return nil } -func (node Node) createFileAt(path string, s *server.Server) error { +func (node Node) createFileAt(path string, s *repo.Server) error { f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600) defer f.Close() diff --git a/server/blob.go b/repo/blob.go similarity index 98% rename from server/blob.go rename to repo/blob.go index 093a1033a..81c8a629f 100644 --- a/server/blob.go +++ b/repo/blob.go @@ -1,4 +1,4 @@ -package server +package repo import ( "bytes" diff --git a/repo/doc.go b/repo/doc.go new file mode 100644 index 000000000..bbc8a6f8e --- /dev/null +++ b/repo/doc.go @@ -0,0 +1,2 @@ +// Package repo implements a restic repository on top of a backend. +package repo diff --git a/server/index.go b/repo/index.go similarity index 99% rename from server/index.go rename to repo/index.go index a6271ff69..2854859c1 100644 --- a/server/index.go +++ b/repo/index.go @@ -1,4 +1,4 @@ -package server +package repo import ( "encoding/json" diff --git a/server/index_test.go b/repo/index_test.go similarity index 95% rename from server/index_test.go rename to repo/index_test.go index 149fdc468..2cc4a971c 100644 --- a/server/index_test.go +++ b/repo/index_test.go @@ -1,4 +1,4 @@ -package server_test +package repo_test import ( "bytes" @@ -8,7 +8,7 @@ import ( "github.com/restic/restic/backend" "github.com/restic/restic/pack" - "github.com/restic/restic/server" + "github.com/restic/restic/repo" . "github.com/restic/restic/test" ) @@ -30,7 +30,7 @@ func TestIndexSerialize(t *testing.T) { } tests := []testEntry{} - idx := server.NewIndex() + idx := repo.NewIndex() // create 50 packs with 20 blobs each for i := 0; i < 50; i++ { @@ -58,7 +58,7 @@ func TestIndexSerialize(t *testing.T) { err := idx.Encode(wr) OK(t, err) - idx2, err := server.DecodeIndex(wr) + idx2, err := repo.DecodeIndex(wr) OK(t, err) Assert(t, idx2 != nil, "nil returned for decoded index") @@ -113,7 +113,7 @@ func TestIndexSerialize(t *testing.T) { err = idx2.Encode(wr3) OK(t, err) - idx3, err := server.DecodeIndex(wr3) + idx3, err := repo.DecodeIndex(wr3) OK(t, err) Assert(t, idx3 != nil, "nil returned for decoded index") @@ -138,7 +138,7 @@ func TestIndexSerialize(t *testing.T) { } func TestIndexSize(t *testing.T) { - idx := server.NewIndex() + idx := repo.NewIndex() packs := 200 blobs := 100 @@ -210,7 +210,7 @@ var exampleTests = []struct { } func TestIndexUnserialize(t *testing.T) { - idx, err := server.DecodeIndex(bytes.NewReader(docExample)) + idx, err := repo.DecodeIndex(bytes.NewReader(docExample)) OK(t, err) for _, test := range exampleTests { diff --git a/server/key.go b/repo/key.go similarity index 99% rename from server/key.go rename to repo/key.go index 1b0965b37..7ea31407b 100644 --- a/server/key.go +++ b/repo/key.go @@ -1,4 +1,4 @@ -package server +package repo import ( "crypto/rand" diff --git a/server/pool.go b/repo/pool.go similarity index 94% rename from server/pool.go rename to repo/pool.go index 304d20e1b..32100a3bd 100644 --- a/server/pool.go +++ b/repo/pool.go @@ -1,4 +1,4 @@ -package server +package repo import ( "sync" diff --git a/server/server.go b/repo/server.go similarity index 99% rename from server/server.go rename to repo/server.go index c6fc9732c..9bafa01b7 100644 --- a/server/server.go +++ b/repo/server.go @@ -1,4 +1,4 @@ -package server +package repo import ( "bytes" diff --git a/server/server_test.go b/repo/server_test.go similarity index 99% rename from server/server_test.go rename to repo/server_test.go index 0f44def1c..99de35701 100644 --- a/server/server_test.go +++ b/repo/server_test.go @@ -1,4 +1,4 @@ -package server_test +package repo_test import ( "bytes" diff --git a/restorer.go b/restorer.go index cebd9c894..26f605611 100644 --- a/restorer.go +++ b/restorer.go @@ -7,14 +7,14 @@ import ( "syscall" "github.com/restic/restic/backend" - "github.com/restic/restic/server" + "github.com/restic/restic/repo" "github.com/juju/errors" ) // Restorer is used to restore a snapshot to a directory. type Restorer struct { - s *server.Server + s *repo.Server sn *Snapshot Error func(dir string, node *Node, err error) error @@ -24,7 +24,7 @@ type Restorer struct { var restorerAbortOnAllErrors = func(str string, node *Node, err error) error { return err } // NewRestorer creates a restorer preloaded with the content from the snapshot id. -func NewRestorer(s *server.Server, id backend.ID) (*Restorer, error) { +func NewRestorer(s *repo.Server, id backend.ID) (*Restorer, error) { r := &Restorer{s: s, Error: restorerAbortOnAllErrors} var err error diff --git a/server/doc.go b/server/doc.go deleted file mode 100644 index 9e1f227a2..000000000 --- a/server/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package server implements a restic repository on top of a backend. -package server diff --git a/snapshot.go b/snapshot.go index a928e27ad..f32425f1f 100644 --- a/snapshot.go +++ b/snapshot.go @@ -9,7 +9,7 @@ import ( "time" "github.com/restic/restic/backend" - "github.com/restic/restic/server" + "github.com/restic/restic/repo" ) type Snapshot struct { @@ -50,7 +50,7 @@ func NewSnapshot(paths []string) (*Snapshot, error) { return sn, nil } -func LoadSnapshot(s *server.Server, id backend.ID) (*Snapshot, error) { +func LoadSnapshot(s *repo.Server, id backend.ID) (*Snapshot, error) { sn := &Snapshot{id: id} err := s.LoadJSONUnpacked(backend.Snapshot, id, sn) if err != nil { diff --git a/test/backend.go b/test/backend.go index 5a2524425..31b824155 100644 --- a/test/backend.go +++ b/test/backend.go @@ -10,14 +10,14 @@ import ( "github.com/restic/restic" "github.com/restic/restic/backend" "github.com/restic/restic/backend/local" - "github.com/restic/restic/server" + "github.com/restic/restic/repo" ) var TestPassword = flag.String("test.password", "", `use this password for repositories created during tests (default: "geheim")`) var TestCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)") var TestTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)") -func SetupBackend(t testing.TB) *server.Server { +func SetupBackend(t testing.TB) *repo.Server { tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-") OK(t, err) @@ -29,12 +29,12 @@ func SetupBackend(t testing.TB) *server.Server { err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache")) OK(t, err) - s := server.NewServer(b) + s := repo.NewServer(b) OK(t, s.Init(*TestPassword)) return s } -func TeardownBackend(t testing.TB, s *server.Server) { +func TeardownBackend(t testing.TB, s *repo.Server) { if !*TestCleanup { l := s.Backend().(*local.Local) t.Logf("leaving local backend at %s\n", l.Location()) @@ -44,7 +44,7 @@ func TeardownBackend(t testing.TB, s *server.Server) { OK(t, s.Delete()) } -func SnapshotDir(t testing.TB, server *server.Server, path string, parent backend.ID) *restic.Snapshot { +func SnapshotDir(t testing.TB, server *repo.Server, path string, parent backend.ID) *restic.Snapshot { arch := restic.NewArchiver(server) sn, _, err := arch.Snapshot(nil, []string{path}, parent) OK(t, err) diff --git a/tree.go b/tree.go index f059d67dd..d43a119e7 100644 --- a/tree.go +++ b/tree.go @@ -8,7 +8,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 Tree struct { @@ -30,7 +30,7 @@ func (t Tree) String() string { return fmt.Sprintf("Tree<%d nodes>", len(t.Nodes)) } -func LoadTree(s *server.Server, id backend.ID) (*Tree, error) { +func LoadTree(s *repo.Server, id backend.ID) (*Tree, error) { tree := &Tree{} err := s.LoadJSONPack(pack.Tree, id, tree) if err != nil { diff --git a/walk.go b/walk.go index 2ed5df070..a0f1566da 100644 --- a/walk.go +++ b/walk.go @@ -5,7 +5,7 @@ import ( "github.com/restic/restic/backend" "github.com/restic/restic/debug" - "github.com/restic/restic/server" + "github.com/restic/restic/repo" ) type WalkTreeJob struct { @@ -16,7 +16,7 @@ type WalkTreeJob struct { Tree *Tree } -func walkTree(s *server.Server, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { +func walkTree(s *repo.Server, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { debug.Log("walkTree", "start on %q (%v)", path, treeID.Str()) t, err := LoadTree(s, treeID) @@ -41,7 +41,7 @@ func walkTree(s *server.Server, path string, treeID backend.ID, done chan struct // WalkTree walks the tree specified by id recursively and sends a job for each // file and directory it finds. When the channel done is closed, processing // stops. -func WalkTree(server *server.Server, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { +func WalkTree(server *repo.Server, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { debug.Log("WalkTree", "start on %v", id.Str()) walkTree(server, "", id, done, jobCh) close(jobCh)