2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-29 16:23:59 +00:00

Move package 'repo' to package 'repository'

This commit is contained in:
Alexander Neumann 2015-05-09 23:52:03 +02:00
parent b2dcdf00e3
commit 232c472836
22 changed files with 62 additions and 62 deletions

View File

@ -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),

View File

@ -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

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/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

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/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)

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/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)

View File

@ -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)
}

View File

@ -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

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/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 {

View File

@ -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()

View File

@ -1,4 +1,4 @@
package repo
package repository
import (
"bytes"

View File

@ -1,2 +1,2 @@
// Package repo implements a restic repository on top of a backend.
package repo
package repository

View File

@ -1,4 +1,4 @@
package repo
package repository
import (
"encoding/json"

View File

@ -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 {

View File

@ -1,4 +1,4 @@
package repo
package repository
import (
"crypto/rand"

View File

@ -1,4 +1,4 @@
package repo
package repository
import (
"sync"

View File

@ -1,4 +1,4 @@
package repo
package repository
import (
"bytes"

View File

@ -1,4 +1,4 @@
package repo_test
package repository_test
import (
"bytes"

View File

@ -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

View File

@ -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 {

View File

@ -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)

View File

@ -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 {

View File

@ -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)