From 232c472836cb43bae6a178bbea5834c188a29e15 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 9 May 2015 23:52:03 +0200 Subject: [PATCH] Move package 'repo' to package 'repository' --- 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 ++++---- {repo => repository}/blob.go | 2 +- {repo => repository}/doc.go | 2 +- {repo => repository}/index.go | 2 +- {repo => repository}/index_test.go | 14 +++++++------- {repo => repository}/key.go | 2 +- {repo => repository}/pool.go | 2 +- {repo => repository}/repository.go | 2 +- {repo => repository}/repository_test.go | 2 +- restorer.go | 6 +++--- snapshot.go | 4 ++-- test/backend.go | 10 +++++----- tree.go | 4 ++-- walk.go | 6 +++--- 22 files changed, 62 insertions(+), 62 deletions(-) rename {repo => repository}/blob.go (97%) rename {repo => repository}/doc.go (78%) rename {repo => repository}/index.go (99%) rename {repo => repository}/index_test.go (94%) rename {repo => repository}/key.go (99%) rename {repo => repository}/pool.go (93%) rename {repo => repository}/repository.go (99%) rename {repo => repository}/repository_test.go (99%) diff --git a/archiver.go b/archiver.go index f4f474563..8a0db8b7b 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/repo" + "github.com/restic/restic/repository" "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 { - repo *repo.Repo + repo *repository.Repo blobToken chan struct{} @@ -39,7 +39,7 @@ type Archiver struct { } // NewArchiver returns a new archiver. -func NewArchiver(repo *repo.Repo) *Archiver { +func NewArchiver(repo *repository.Repo) *Archiver { arch := &Archiver{ repo: repo, blobToken: make(chan struct{}, maxConcurrentBlobs), diff --git a/cache.go b/cache.go index 47bfbac76..74f31f06e 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/repo" + "github.com/restic/restic/repository" ) // Cache is used to locally cache items from a repository. @@ -18,7 +18,7 @@ type Cache struct { base string } -func NewCache(repo *repo.Repo) (*Cache, error) { +func NewCache(repo *repository.Repo) (*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 repository any more. -func (c *Cache) Clear(repo *repo.Repo) error { +func (c *Cache) Clear(repo *repository.Repo) 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 b90d85d45..e10a9071b 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/repo" + "github.com/restic/restic/repository" ) type CmdCat struct{} @@ -107,7 +107,7 @@ func (cmd CmdCat) Execute(args []string) error { dec := json.NewDecoder(rd) - var key repo.Key + var key repository.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 cdb2b4c18..2c13736ce 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/repo" + "github.com/restic/restic/repository" ) 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(repo *repo.Repo, id backend.ID, path string) ([]findResult, error) { +func (c CmdFind) findInTree(repo *repository.Repo, id backend.ID, path string) ([]findResult, error) { debug.Log("restic.find", "checking tree %v\n", id) tree, err := restic.LoadTree(repo, id) if err != nil { @@ -105,7 +105,7 @@ func (c CmdFind) findInTree(repo *repo.Repo, id backend.ID, path string) ([]find return results, nil } -func (c CmdFind) findInSnapshot(repo *repo.Repo, name string) error { +func (c CmdFind) findInSnapshot(repo *repository.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) diff --git a/cmd/restic/cmd_fsck.go b/cmd/restic/cmd_fsck.go index 6fbb4ddca..a50dc6379 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/repo" + "github.com/restic/restic/repository" ) type CmdFsck struct { @@ -34,7 +34,7 @@ func init() { } } -func fsckFile(opts CmdFsck, repo *repo.Repo, IDs []backend.ID) (uint64, error) { +func fsckFile(opts CmdFsck, repo *repository.Repo, IDs []backend.ID) (uint64, error) { debug.Log("restic.fsckFile", "checking file %v", IDs) var bytes uint64 @@ -77,7 +77,7 @@ func fsckFile(opts CmdFsck, repo *repo.Repo, IDs []backend.ID) (uint64, error) { return bytes, nil } -func fsckTree(opts CmdFsck, repo *repo.Repo, id backend.ID) error { +func fsckTree(opts CmdFsck, repo *repository.Repo, id backend.ID) error { debug.Log("restic.fsckTree", "checking tree %v", id.Str()) tree, err := restic.LoadTree(repo, id) @@ -157,7 +157,7 @@ func fsckTree(opts CmdFsck, repo *repo.Repo, id backend.ID) error { return firstErr } -func fsckSnapshot(opts CmdFsck, repo *repo.Repo, id backend.ID) error { +func fsckSnapshot(opts CmdFsck, repo *repository.Repo, id backend.ID) error { debug.Log("restic.fsck", "checking snapshot %v\n", id) sn, err := restic.LoadSnapshot(repo, id) diff --git a/cmd/restic/cmd_key.go b/cmd/restic/cmd_key.go index b1abdad69..3ba1a5b49 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/repo" + "github.com/restic/restic/repository" ) type CmdKey struct{} @@ -21,7 +21,7 @@ func init() { } } -func listKeys(s *repo.Repo) error { +func listKeys(s *repository.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 *repo.Repo) error { defer close(done) for name := range s.List(backend.Key, done) { - k, err := repo.LoadKey(s, name) + k, err := repository.LoadKey(s, name) if err != nil { fmt.Fprintf(os.Stderr, "LoadKey() failed: %v\n", err) continue @@ -56,7 +56,7 @@ func listKeys(s *repo.Repo) error { return nil } -func addKey(s *repo.Repo) error { +func addKey(s *repository.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 *repo.Repo) error { return errors.New("passwords do not match") } - id, err := repo.AddKey(s, pw, s.Key()) + id, err := repository.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 *repo.Repo) error { return nil } -func deleteKey(repo *repo.Repo, name string) error { +func deleteKey(repo *repository.Repo, name string) error { if name == repo.KeyName() { return errors.New("refusing to remove key currently used to access repository") } @@ -88,7 +88,7 @@ func deleteKey(repo *repo.Repo, name string) error { return nil } -func changePassword(s *repo.Repo) error { +func changePassword(s *repository.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 *repo.Repo) error { } // add new key - id, err := repo.AddKey(s, pw, s.Key()) + id, err := repository.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 c9d67ed43..d38968b12 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/repo" + "github.com/restic/restic/repository" ) type CmdLs struct{} @@ -38,7 +38,7 @@ func printNode(prefix string, n *restic.Node) string { } } -func printTree(prefix string, repo *repo.Repo, id backend.ID) error { +func printTree(prefix string, repo *repository.Repo, id backend.ID) error { tree, err := restic.LoadTree(repo, id) if err != nil { return err diff --git a/cmd/restic/main.go b/cmd/restic/main.go index f34ecd4ac..13bec152a 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/repo" + "github.com/restic/restic/repository" ) var version = "compiled manually" @@ -72,7 +72,7 @@ func (cmd CmdInit) Execute(args []string) error { os.Exit(1) } - s := repo.New(be) + s := repository.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() (*repo.Repo, error) { +func OpenRepo() (*repository.Repo, error) { if opts.Repo == "" { return nil, errors.New("Please specify repository location (-r)") } @@ -143,7 +143,7 @@ func OpenRepo() (*repo.Repo, error) { return nil, err } - s := repo.New(be) + s := repository.New(be) err = s.SearchKey(readPassword("RESTIC_PASSWORD", "enter password for repository: ")) if err != nil { diff --git a/node.go b/node.go index 517cbb31b..2130f0927 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/repo" + "github.com/restic/restic/repository" ) // Node is a file, directory or other item in a backup. @@ -43,7 +43,7 @@ type Node struct { path string err error - blobs repo.Blobs + blobs repository.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, repo *repo.Repo) error { +func (node *Node) CreateAt(path string, repo *repository.Repo) 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, repo *repo.Repo) error { +func (node Node) createFileAt(path string, repo *repository.Repo) error { f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600) defer f.Close() diff --git a/repo/blob.go b/repository/blob.go similarity index 97% rename from repo/blob.go rename to repository/blob.go index 81c8a629f..12e1ed64b 100644 --- a/repo/blob.go +++ b/repository/blob.go @@ -1,4 +1,4 @@ -package repo +package repository import ( "bytes" diff --git a/repo/doc.go b/repository/doc.go similarity index 78% rename from repo/doc.go rename to repository/doc.go index bbc8a6f8e..b69b865e7 100644 --- a/repo/doc.go +++ b/repository/doc.go @@ -1,2 +1,2 @@ // Package repo implements a restic repository on top of a backend. -package repo +package repository diff --git a/repo/index.go b/repository/index.go similarity index 99% rename from repo/index.go rename to repository/index.go index 2854859c1..be7904c66 100644 --- a/repo/index.go +++ b/repository/index.go @@ -1,4 +1,4 @@ -package repo +package repository import ( "encoding/json" diff --git a/repo/index_test.go b/repository/index_test.go similarity index 94% rename from repo/index_test.go rename to repository/index_test.go index 2cc4a971c..9e3749ed3 100644 --- a/repo/index_test.go +++ b/repository/index_test.go @@ -1,4 +1,4 @@ -package repo_test +package repository_test import ( "bytes" @@ -8,7 +8,7 @@ import ( "github.com/restic/restic/backend" "github.com/restic/restic/pack" - "github.com/restic/restic/repo" + "github.com/restic/restic/repository" . "github.com/restic/restic/test" ) @@ -30,7 +30,7 @@ func TestIndexSerialize(t *testing.T) { } tests := []testEntry{} - idx := repo.NewIndex() + idx := repository.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 := repo.DecodeIndex(wr) + idx2, err := repository.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 := repo.DecodeIndex(wr3) + idx3, err := repository.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 := repo.NewIndex() + idx := repository.NewIndex() packs := 200 blobs := 100 @@ -210,7 +210,7 @@ var exampleTests = []struct { } func TestIndexUnserialize(t *testing.T) { - idx, err := repo.DecodeIndex(bytes.NewReader(docExample)) + idx, err := repository.DecodeIndex(bytes.NewReader(docExample)) OK(t, err) for _, test := range exampleTests { diff --git a/repo/key.go b/repository/key.go similarity index 99% rename from repo/key.go rename to repository/key.go index d99a1408e..049d253cc 100644 --- a/repo/key.go +++ b/repository/key.go @@ -1,4 +1,4 @@ -package repo +package repository import ( "crypto/rand" diff --git a/repo/pool.go b/repository/pool.go similarity index 93% rename from repo/pool.go rename to repository/pool.go index 32100a3bd..258d08d92 100644 --- a/repo/pool.go +++ b/repository/pool.go @@ -1,4 +1,4 @@ -package repo +package repository import ( "sync" diff --git a/repo/repository.go b/repository/repository.go similarity index 99% rename from repo/repository.go rename to repository/repository.go index 80d392f89..b3f171497 100644 --- a/repo/repository.go +++ b/repository/repository.go @@ -1,4 +1,4 @@ -package repo +package repository import ( "bytes" diff --git a/repo/repository_test.go b/repository/repository_test.go similarity index 99% rename from repo/repository_test.go rename to repository/repository_test.go index 5620b923f..fe9f5c9d4 100644 --- a/repo/repository_test.go +++ b/repository/repository_test.go @@ -1,4 +1,4 @@ -package repo_test +package repository_test import ( "bytes" diff --git a/restorer.go b/restorer.go index be0e6e347..7762c8d3f 100644 --- a/restorer.go +++ b/restorer.go @@ -7,14 +7,14 @@ import ( "syscall" "github.com/restic/restic/backend" - "github.com/restic/restic/repo" + "github.com/restic/restic/repository" "github.com/juju/errors" ) // Restorer is used to restore a snapshot to a directory. type Restorer struct { - repo *repo.Repo + repo *repository.Repo 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(repo *repo.Repo, id backend.ID) (*Restorer, error) { +func NewRestorer(repo *repository.Repo, id backend.ID) (*Restorer, error) { r := &Restorer{repo: repo, Error: restorerAbortOnAllErrors} var err error diff --git a/snapshot.go b/snapshot.go index 776e35790..7d5fb9851 100644 --- a/snapshot.go +++ b/snapshot.go @@ -9,7 +9,7 @@ import ( "time" "github.com/restic/restic/backend" - "github.com/restic/restic/repo" + "github.com/restic/restic/repository" ) type Snapshot struct { @@ -50,7 +50,7 @@ func NewSnapshot(paths []string) (*Snapshot, error) { return sn, nil } -func LoadSnapshot(repo *repo.Repo, id backend.ID) (*Snapshot, error) { +func LoadSnapshot(repo *repository.Repo, id backend.ID) (*Snapshot, error) { sn := &Snapshot{id: id} err := repo.LoadJSONUnpacked(backend.Snapshot, id, sn) if err != nil { diff --git a/test/backend.go b/test/backend.go index 6886fe6fd..80d022d74 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/repo" + "github.com/restic/restic/repository" ) var TestPassword = flag.String("test.password", "geheim", `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 SetupRepo(t testing.TB) *repo.Repo { +func SetupRepo(t testing.TB) *repository.Repo { tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-") OK(t, err) @@ -29,12 +29,12 @@ func SetupRepo(t testing.TB) *repo.Repo { err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache")) OK(t, err) - repo := repo.New(b) + repo := repository.New(b) OK(t, repo.Init(*TestPassword)) return repo } -func TeardownRepo(t testing.TB, repo *repo.Repo) { +func TeardownRepo(t testing.TB, repo *repository.Repo) { if !*TestCleanup { l := repo.Backend().(*local.Local) t.Logf("leaving local backend at %s\n", l.Location()) @@ -44,7 +44,7 @@ func TeardownRepo(t testing.TB, repo *repo.Repo) { OK(t, repo.Delete()) } -func SnapshotDir(t testing.TB, repo *repo.Repo, path string, parent backend.ID) *restic.Snapshot { +func SnapshotDir(t testing.TB, repo *repository.Repo, path string, parent backend.ID) *restic.Snapshot { arch := restic.NewArchiver(repo) sn, _, err := arch.Snapshot(nil, []string{path}, parent) OK(t, err) diff --git a/tree.go b/tree.go index 0fccf5082..d529fb3be 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/repo" + "github.com/restic/restic/repository" ) type Tree struct { @@ -30,7 +30,7 @@ func (t Tree) String() string { return fmt.Sprintf("Tree<%d nodes>", len(t.Nodes)) } -func LoadTree(repo *repo.Repo, id backend.ID) (*Tree, error) { +func LoadTree(repo *repository.Repo, id backend.ID) (*Tree, error) { tree := &Tree{} err := repo.LoadJSONPack(pack.Tree, id, tree) if err != nil { diff --git a/walk.go b/walk.go index f666d5d38..c26adeaae 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/repo" + "github.com/restic/restic/repository" ) type WalkTreeJob struct { @@ -16,7 +16,7 @@ type WalkTreeJob struct { Tree *Tree } -func walkTree(repo *repo.Repo, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { +func walkTree(repo *repository.Repo, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { debug.Log("walkTree", "start on %q (%v)", path, treeID.Str()) t, err := LoadTree(repo, treeID) @@ -41,7 +41,7 @@ func walkTree(repo *repo.Repo, 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(repo *repo.Repo, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { +func WalkTree(repo *repository.Repo, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { debug.Log("WalkTree", "start on %v", id.Str()) walkTree(repo, "", id, done, jobCh) close(jobCh)