Merge pull request #180 from restic/rename-repo-repository

Change repository name again
This commit is contained in:
Alexander Neumann 2015-05-10 00:04:35 +02:00
commit 7a32a6b389
22 changed files with 109 additions and 109 deletions

View file

@ -15,7 +15,7 @@ import (
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/pack" "github.com/restic/restic/pack"
"github.com/restic/restic/pipe" "github.com/restic/restic/pipe"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
"github.com/juju/errors" "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. // Archiver is used to backup a set of directories.
type Archiver struct { type Archiver struct {
repo *repo.Repo repo *repository.Repository
blobToken chan struct{} blobToken chan struct{}
@ -39,7 +39,7 @@ type Archiver struct {
} }
// NewArchiver returns a new archiver. // NewArchiver returns a new archiver.
func NewArchiver(repo *repo.Repo) *Archiver { func NewArchiver(repo *repository.Repository) *Archiver {
arch := &Archiver{ arch := &Archiver{
repo: repo, repo: repo,
blobToken: make(chan struct{}, maxConcurrentBlobs), blobToken: make(chan struct{}, maxConcurrentBlobs),

View file

@ -10,7 +10,7 @@ import (
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/debug" "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. // Cache is used to locally cache items from a repository.
@ -18,7 +18,7 @@ type Cache struct {
base string base string
} }
func NewCache(repo *repo.Repo) (*Cache, error) { func NewCache(repo *repository.Repository) (*Cache, error) {
cacheDir, err := getCacheDir() cacheDir, err := getCacheDir()
if err != nil { if err != nil {
return nil, err 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. // 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.Repository) error {
list, err := c.list(backend.Snapshot) list, err := c.list(backend.Snapshot)
if err != nil { if err != nil {
return err return err

View file

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

View file

@ -8,7 +8,7 @@ import (
"github.com/restic/restic" "github.com/restic/restic"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
) )
type findResult struct { 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) 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.Repository, id backend.ID, path string) ([]findResult, error) {
debug.Log("restic.find", "checking tree %v\n", id) debug.Log("restic.find", "checking tree %v\n", id)
tree, err := restic.LoadTree(repo, id) tree, err := restic.LoadTree(repo, id)
if err != nil { if err != nil {
@ -105,7 +105,7 @@ func (c CmdFind) findInTree(repo *repo.Repo, id backend.ID, path string) ([]find
return results, nil return results, nil
} }
func (c CmdFind) findInSnapshot(repo *repo.Repo, name string) error { func (c CmdFind) findInSnapshot(repo *repository.Repository, name string) error {
debug.Log("restic.find", "searching in snapshot %s\n for entries within [%s %s]", name, c.oldest, c.newest) debug.Log("restic.find", "searching in snapshot %s\n for entries within [%s %s]", name, c.oldest, c.newest)
id, err := backend.ParseID(name) id, err := backend.ParseID(name)

View file

@ -10,7 +10,7 @@ import (
"github.com/restic/restic/crypto" "github.com/restic/restic/crypto"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/pack" "github.com/restic/restic/pack"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
) )
type CmdFsck struct { 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.Repository, IDs []backend.ID) (uint64, error) {
debug.Log("restic.fsckFile", "checking file %v", IDs) debug.Log("restic.fsckFile", "checking file %v", IDs)
var bytes uint64 var bytes uint64
@ -77,7 +77,7 @@ func fsckFile(opts CmdFsck, repo *repo.Repo, IDs []backend.ID) (uint64, error) {
return bytes, nil return bytes, nil
} }
func fsckTree(opts CmdFsck, repo *repo.Repo, id backend.ID) error { func fsckTree(opts CmdFsck, repo *repository.Repository, id backend.ID) error {
debug.Log("restic.fsckTree", "checking tree %v", id.Str()) debug.Log("restic.fsckTree", "checking tree %v", id.Str())
tree, err := restic.LoadTree(repo, id) tree, err := restic.LoadTree(repo, id)
@ -157,7 +157,7 @@ func fsckTree(opts CmdFsck, repo *repo.Repo, id backend.ID) error {
return firstErr return firstErr
} }
func fsckSnapshot(opts CmdFsck, repo *repo.Repo, id backend.ID) error { func fsckSnapshot(opts CmdFsck, repo *repository.Repository, id backend.ID) error {
debug.Log("restic.fsck", "checking snapshot %v\n", id) debug.Log("restic.fsck", "checking snapshot %v\n", id)
sn, err := restic.LoadSnapshot(repo, id) sn, err := restic.LoadSnapshot(repo, id)

View file

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

View file

@ -14,7 +14,7 @@ import (
"github.com/restic/restic/backend/local" "github.com/restic/restic/backend/local"
"github.com/restic/restic/backend/sftp" "github.com/restic/restic/backend/sftp"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
) )
var version = "compiled manually" var version = "compiled manually"
@ -72,7 +72,7 @@ func (cmd CmdInit) Execute(args []string) error {
os.Exit(1) os.Exit(1)
} }
s := repo.New(be) s := repository.New(be)
err = s.Init(pw) err = s.Init(pw)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "creating key in backend at %s failed: %v\n", opts.Repo, err) 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...) return sftp.Create(url.Path[1:], "ssh", args...)
} }
func OpenRepo() (*repo.Repo, error) { func OpenRepo() (*repository.Repository, error) {
if opts.Repo == "" { if opts.Repo == "" {
return nil, errors.New("Please specify repository location (-r)") return nil, errors.New("Please specify repository location (-r)")
} }
@ -143,7 +143,7 @@ func OpenRepo() (*repo.Repo, error) {
return nil, err return nil, err
} }
s := repo.New(be) s := repository.New(be)
err = s.SearchKey(readPassword("RESTIC_PASSWORD", "enter password for repository: ")) err = s.SearchKey(readPassword("RESTIC_PASSWORD", "enter password for repository: "))
if err != nil { if err != nil {

View file

@ -14,7 +14,7 @@ import (
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/pack" "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. // Node is a file, directory or other item in a backup.
@ -43,7 +43,7 @@ type Node struct {
path string path string
err error err error
blobs repo.Blobs blobs repository.Blobs
} }
func (node Node) String() string { 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. // 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.Repository) error {
switch node.Type { switch node.Type {
case "dir": case "dir":
if err := node.createDirAt(path); err != nil { if err := node.createDirAt(path); err != nil {
@ -176,7 +176,7 @@ func (node Node) createDirAt(path string) error {
return nil return nil
} }
func (node Node) createFileAt(path string, repo *repo.Repo) error { func (node Node) createFileAt(path string, repo *repository.Repository) error {
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600) f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600)
defer f.Close() defer f.Close()

View file

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

View file

@ -1,2 +1,2 @@
// Package repo implements a restic repository on top of a backend. // 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 ( import (
"encoding/json" "encoding/json"

View file

@ -1,4 +1,4 @@
package repo_test package repository_test
import ( import (
"bytes" "bytes"
@ -8,7 +8,7 @@ import (
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/pack" "github.com/restic/restic/pack"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
. "github.com/restic/restic/test" . "github.com/restic/restic/test"
) )
@ -30,7 +30,7 @@ func TestIndexSerialize(t *testing.T) {
} }
tests := []testEntry{} tests := []testEntry{}
idx := repo.NewIndex() idx := repository.NewIndex()
// create 50 packs with 20 blobs each // create 50 packs with 20 blobs each
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {
@ -58,7 +58,7 @@ func TestIndexSerialize(t *testing.T) {
err := idx.Encode(wr) err := idx.Encode(wr)
OK(t, err) OK(t, err)
idx2, err := repo.DecodeIndex(wr) idx2, err := repository.DecodeIndex(wr)
OK(t, err) OK(t, err)
Assert(t, idx2 != nil, Assert(t, idx2 != nil,
"nil returned for decoded index") "nil returned for decoded index")
@ -113,7 +113,7 @@ func TestIndexSerialize(t *testing.T) {
err = idx2.Encode(wr3) err = idx2.Encode(wr3)
OK(t, err) OK(t, err)
idx3, err := repo.DecodeIndex(wr3) idx3, err := repository.DecodeIndex(wr3)
OK(t, err) OK(t, err)
Assert(t, idx3 != nil, Assert(t, idx3 != nil,
"nil returned for decoded index") "nil returned for decoded index")
@ -138,7 +138,7 @@ func TestIndexSerialize(t *testing.T) {
} }
func TestIndexSize(t *testing.T) { func TestIndexSize(t *testing.T) {
idx := repo.NewIndex() idx := repository.NewIndex()
packs := 200 packs := 200
blobs := 100 blobs := 100
@ -210,7 +210,7 @@ var exampleTests = []struct {
} }
func TestIndexUnserialize(t *testing.T) { func TestIndexUnserialize(t *testing.T) {
idx, err := repo.DecodeIndex(bytes.NewReader(docExample)) idx, err := repository.DecodeIndex(bytes.NewReader(docExample))
OK(t, err) OK(t, err)
for _, test := range exampleTests { for _, test := range exampleTests {

View file

@ -1,4 +1,4 @@
package repo package repository
import ( import (
"crypto/rand" "crypto/rand"
@ -49,12 +49,12 @@ type Key struct {
// createMasterKey creates a new master key in the given backend and encrypts // createMasterKey creates a new master key in the given backend and encrypts
// it with the password. // it with the password.
func createMasterKey(s *Repo, password string) (*Key, error) { func createMasterKey(s *Repository, password string) (*Key, error) {
return AddKey(s, password, nil) return AddKey(s, password, nil)
} }
// OpenKey tries do decrypt the key specified by name with the given password. // OpenKey tries do decrypt the key specified by name with the given password.
func OpenKey(s *Repo, name string, password string) (*Key, error) { func OpenKey(s *Repository, name string, password string) (*Key, error) {
k, err := LoadKey(s, name) k, err := LoadKey(s, name)
if err != nil { if err != nil {
return nil, err return nil, err
@ -94,7 +94,7 @@ func OpenKey(s *Repo, name string, password string) (*Key, error) {
// SearchKey tries to decrypt all keys in the backend with the given password. // SearchKey tries to decrypt all keys in the backend with the given password.
// If none could be found, ErrNoKeyFound is returned. // If none could be found, ErrNoKeyFound is returned.
func SearchKey(s *Repo, password string) (*Key, error) { func SearchKey(s *Repository, password string) (*Key, error) {
// try all keys in repo // try all keys in repo
done := make(chan struct{}) done := make(chan struct{})
defer close(done) defer close(done)
@ -111,7 +111,7 @@ func SearchKey(s *Repo, password string) (*Key, error) {
} }
// LoadKey loads a key from the backend. // LoadKey loads a key from the backend.
func LoadKey(s *Repo, name string) (*Key, error) { func LoadKey(s *Repository, name string) (*Key, error) {
// extract data from repo // extract data from repo
rd, err := s.be.Get(backend.Key, name) rd, err := s.be.Get(backend.Key, name)
if err != nil { if err != nil {
@ -131,7 +131,7 @@ func LoadKey(s *Repo, name string) (*Key, error) {
} }
// AddKey adds a new key to an already existing repository. // AddKey adds a new key to an already existing repository.
func AddKey(s *Repo, password string, template *crypto.Key) (*Key, error) { func AddKey(s *Repository, password string, template *crypto.Key) (*Key, error) {
// fill meta data about key // fill meta data about key
newkey := &Key{ newkey := &Key{
Created: time.Now(), Created: time.Now(),

View file

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

View file

@ -1,4 +1,4 @@
package repo package repository
import ( import (
"bytes" "bytes"
@ -26,8 +26,8 @@ type Config struct {
ChunkerPolynomial chunker.Pol `json:"chunker_polynomial"` ChunkerPolynomial chunker.Pol `json:"chunker_polynomial"`
} }
// Repo is used to access a repository in a backend. // Repository is used to access a repository in a backend.
type Repo struct { type Repository struct {
be backend.Backend be backend.Backend
Config Config Config Config
key *crypto.Key key *crypto.Key
@ -38,8 +38,8 @@ type Repo struct {
packs []*pack.Packer packs []*pack.Packer
} }
func New(be backend.Backend) *Repo { func New(be backend.Backend) *Repository {
return &Repo{ return &Repository{
be: be, be: be,
idx: NewIndex(), idx: NewIndex(),
} }
@ -48,25 +48,25 @@ func New(be backend.Backend) *Repo {
// Find loads the list of all blobs of type t and searches for names which start // Find loads the list of all blobs of type t and searches for names which start
// with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. If // with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. If
// more than one is found, nil and ErrMultipleIDMatches is returned. // more than one is found, nil and ErrMultipleIDMatches is returned.
func (s *Repo) Find(t backend.Type, prefix string) (string, error) { func (s *Repository) Find(t backend.Type, prefix string) (string, error) {
return backend.Find(s.be, t, prefix) return backend.Find(s.be, t, prefix)
} }
// FindSnapshot takes a string and tries to find a snapshot whose ID matches // FindSnapshot takes a string and tries to find a snapshot whose ID matches
// the string as closely as possible. // the string as closely as possible.
func (s *Repo) FindSnapshot(name string) (string, error) { func (s *Repository) FindSnapshot(name string) (string, error) {
return backend.FindSnapshot(s.be, name) return backend.FindSnapshot(s.be, name)
} }
// PrefixLength returns the number of bytes required so that all prefixes of // PrefixLength returns the number of bytes required so that all prefixes of
// all IDs of type t are unique. // all IDs of type t are unique.
func (s *Repo) PrefixLength(t backend.Type) (int, error) { func (s *Repository) PrefixLength(t backend.Type) (int, error) {
return backend.PrefixLength(s.be, t) return backend.PrefixLength(s.be, t)
} }
// Load tries to load and decrypt content identified by t and id from the // Load tries to load and decrypt content identified by t and id from the
// backend. // backend.
func (s *Repo) Load(t backend.Type, id backend.ID) ([]byte, error) { func (s *Repository) Load(t backend.Type, id backend.ID) ([]byte, error) {
debug.Log("Repo.Load", "load %v with id %v", t, id.Str()) debug.Log("Repo.Load", "load %v with id %v", t, id.Str())
// load blob from pack // load blob from pack
@ -102,7 +102,7 @@ func (s *Repo) Load(t backend.Type, id backend.ID) ([]byte, error) {
// LoadBlob tries to load and decrypt content identified by t and id from a // LoadBlob tries to load and decrypt content identified by t and id from a
// pack from the backend. // pack from the backend.
func (s *Repo) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) { func (s *Repository) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
debug.Log("Repo.LoadBlob", "load %v with id %v", t, id.Str()) debug.Log("Repo.LoadBlob", "load %v with id %v", t, id.Str())
// lookup pack // lookup pack
packID, tpe, offset, length, err := s.idx.Lookup(id) packID, tpe, offset, length, err := s.idx.Lookup(id)
@ -151,7 +151,7 @@ func (s *Repo) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
// LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on // LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on
// the item. // the item.
func (s *Repo) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{}) error { func (s *Repository) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{}) error {
// load blob from backend // load blob from backend
rd, err := s.be.Get(t, id.String()) rd, err := s.be.Get(t, id.String())
if err != nil { if err != nil {
@ -178,7 +178,7 @@ func (s *Repo) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{})
// LoadJSONPack calls LoadBlob() to load a blob from the backend, decrypt the // LoadJSONPack calls LoadBlob() to load a blob from the backend, decrypt the
// data and afterwards call json.Unmarshal on the item. // data and afterwards call json.Unmarshal on the item.
func (s *Repo) LoadJSONPack(t pack.BlobType, id backend.ID, item interface{}) error { func (s *Repository) LoadJSONPack(t pack.BlobType, id backend.ID, item interface{}) error {
// lookup pack // lookup pack
packID, _, offset, length, err := s.idx.Lookup(id) packID, _, offset, length, err := s.idx.Lookup(id)
if err != nil { if err != nil {
@ -215,7 +215,7 @@ const maxPackers = 200
// findPacker returns a packer for a new blob of size bytes. Either a new one is // findPacker returns a packer for a new blob of size bytes. Either a new one is
// created or one is returned that already has some blobs. // created or one is returned that already has some blobs.
func (s *Repo) findPacker(size uint) (*pack.Packer, error) { func (s *Repository) findPacker(size uint) (*pack.Packer, error) {
s.pm.Lock() s.pm.Lock()
defer s.pm.Unlock() defer s.pm.Unlock()
@ -242,7 +242,7 @@ func (s *Repo) findPacker(size uint) (*pack.Packer, error) {
} }
// insertPacker appends p to s.packs. // insertPacker appends p to s.packs.
func (s *Repo) insertPacker(p *pack.Packer) { func (s *Repository) insertPacker(p *pack.Packer) {
s.pm.Lock() s.pm.Lock()
defer s.pm.Unlock() defer s.pm.Unlock()
@ -251,7 +251,7 @@ func (s *Repo) insertPacker(p *pack.Packer) {
} }
// savePacker stores p in the backend. // savePacker stores p in the backend.
func (s *Repo) savePacker(p *pack.Packer) error { func (s *Repository) savePacker(p *pack.Packer) error {
debug.Log("Repo.savePacker", "save packer with %d blobs\n", p.Count()) debug.Log("Repo.savePacker", "save packer with %d blobs\n", p.Count())
_, err := p.Finalize() _, err := p.Finalize()
if err != nil { if err != nil {
@ -278,7 +278,7 @@ func (s *Repo) savePacker(p *pack.Packer) error {
} }
// countPacker returns the number of open (unfinished) packers. // countPacker returns the number of open (unfinished) packers.
func (s *Repo) countPacker() int { func (s *Repository) countPacker() int {
s.pm.Lock() s.pm.Lock()
defer s.pm.Unlock() defer s.pm.Unlock()
@ -287,7 +287,7 @@ func (s *Repo) countPacker() int {
// Save encrypts data and stores it to the backend as type t. If data is small // Save encrypts data and stores it to the backend as type t. If data is small
// enough, it will be packed together with other small blobs. // enough, it will be packed together with other small blobs.
func (s *Repo) Save(t pack.BlobType, data []byte, id backend.ID) (backend.ID, error) { func (s *Repository) Save(t pack.BlobType, data []byte, id backend.ID) (backend.ID, error) {
if id == nil { if id == nil {
// compute plaintext hash // compute plaintext hash
id = backend.Hash(data) id = backend.Hash(data)
@ -332,7 +332,7 @@ func (s *Repo) Save(t pack.BlobType, data []byte, id backend.ID) (backend.ID, er
} }
// SaveFrom encrypts data read from rd and stores it in a pack in the backend as type t. // SaveFrom encrypts data read from rd and stores it in a pack in the backend as type t.
func (s *Repo) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error { func (s *Repository) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error {
debug.Log("Repo.SaveFrom", "save id %v (%v, %d bytes)", id.Str(), t, length) debug.Log("Repo.SaveFrom", "save id %v (%v, %d bytes)", id.Str(), t, length)
if id == nil { if id == nil {
return errors.New("id is nil") return errors.New("id is nil")
@ -353,7 +353,7 @@ func (s *Repo) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io.Reade
// SaveJSON serialises item as JSON and encrypts and saves it in a pack in the // SaveJSON serialises item as JSON and encrypts and saves it in a pack in the
// backend as type t. // backend as type t.
func (s *Repo) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) { func (s *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) {
debug.Log("Repo.SaveJSON", "save %v blob", t) debug.Log("Repo.SaveJSON", "save %v blob", t)
buf := getBuf()[:0] buf := getBuf()[:0]
defer freeBuf(buf) defer freeBuf(buf)
@ -372,7 +372,7 @@ func (s *Repo) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) {
// SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the // SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the
// backend as type t, without a pack. It returns the storage hash. // backend as type t, without a pack. It returns the storage hash.
func (s *Repo) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, error) { func (s *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, error) {
// create file // create file
blob, err := s.be.Create() blob, err := s.be.Create()
if err != nil { if err != nil {
@ -409,7 +409,7 @@ func (s *Repo) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, e
} }
// Flush saves all remaining packs. // Flush saves all remaining packs.
func (s *Repo) Flush() error { func (s *Repository) Flush() error {
s.pm.Lock() s.pm.Lock()
defer s.pm.Unlock() defer s.pm.Unlock()
@ -426,22 +426,22 @@ func (s *Repo) Flush() error {
return nil return nil
} }
func (s *Repo) Backend() backend.Backend { func (s *Repository) Backend() backend.Backend {
return s.be return s.be
} }
func (s *Repo) Index() *Index { func (s *Repository) Index() *Index {
return s.idx return s.idx
} }
// SetIndex instructs the repository to use the given index. // SetIndex instructs the repository to use the given index.
func (s *Repo) SetIndex(i *Index) { func (s *Repository) SetIndex(i *Index) {
s.idx = i s.idx = i
} }
// SaveIndex saves all new packs in the index in the backend, returned is the // SaveIndex saves all new packs in the index in the backend, returned is the
// storage ID. // storage ID.
func (s *Repo) SaveIndex() (backend.ID, error) { func (s *Repository) SaveIndex() (backend.ID, error) {
debug.Log("Repo.SaveIndex", "Saving index") debug.Log("Repo.SaveIndex", "Saving index")
// create blob // create blob
@ -483,7 +483,7 @@ func (s *Repo) SaveIndex() (backend.ID, error) {
// LoadIndex loads all index files from the backend and merges them with the // LoadIndex loads all index files from the backend and merges them with the
// current index. // current index.
func (s *Repo) LoadIndex() error { func (s *Repository) LoadIndex() error {
debug.Log("Repo.LoadIndex", "Loading index") debug.Log("Repo.LoadIndex", "Loading index")
done := make(chan struct{}) done := make(chan struct{})
defer close(done) defer close(done)
@ -498,7 +498,7 @@ func (s *Repo) LoadIndex() error {
} }
// loadIndex loads the index id and merges it with the currently used index. // loadIndex loads the index id and merges it with the currently used index.
func (s *Repo) loadIndex(id string) error { func (s *Repository) loadIndex(id string) error {
debug.Log("Repo.loadIndex", "Loading index %v", id[:8]) debug.Log("Repo.loadIndex", "Loading index %v", id[:8])
before := len(s.idx.pack) before := len(s.idx.pack)
@ -532,7 +532,7 @@ func (s *Repo) loadIndex(id string) error {
const repositoryIDSize = sha256.Size const repositoryIDSize = sha256.Size
const RepoVersion = 1 const RepoVersion = 1
func createConfig(s *Repo) (err error) { func createConfig(s *Repository) (err error) {
s.Config.ChunkerPolynomial, err = chunker.RandomPolynomial() s.Config.ChunkerPolynomial, err = chunker.RandomPolynomial()
if err != nil { if err != nil {
return err return err
@ -553,7 +553,7 @@ func createConfig(s *Repo) (err error) {
return err return err
} }
func (s *Repo) loadConfig(cfg *Config) error { func (s *Repository) loadConfig(cfg *Config) error {
err := s.LoadJSONUnpacked(backend.Config, nil, cfg) err := s.LoadJSONUnpacked(backend.Config, nil, cfg)
if err != nil { if err != nil {
return err return err
@ -572,7 +572,7 @@ func (s *Repo) loadConfig(cfg *Config) error {
// SearchKey finds a key with the supplied password, afterwards the config is // SearchKey finds a key with the supplied password, afterwards the config is
// read and parsed. // read and parsed.
func (s *Repo) SearchKey(password string) error { func (s *Repository) SearchKey(password string) error {
key, err := SearchKey(s, password) key, err := SearchKey(s, password)
if err != nil { if err != nil {
return err return err
@ -585,7 +585,7 @@ func (s *Repo) SearchKey(password string) error {
// Init creates a new master key with the supplied password and initializes the // Init creates a new master key with the supplied password and initializes the
// repository config. // repository config.
func (s *Repo) Init(password string) error { func (s *Repository) Init(password string) error {
has, err := s.Test(backend.Config, "") has, err := s.Test(backend.Config, "")
if err != nil { if err != nil {
return err return err
@ -604,7 +604,7 @@ func (s *Repo) Init(password string) error {
return createConfig(s) return createConfig(s)
} }
func (s *Repo) Decrypt(ciphertext []byte) ([]byte, error) { func (s *Repository) Decrypt(ciphertext []byte) ([]byte, error) {
if s.key == nil { if s.key == nil {
return nil, errors.New("key for repository not set") return nil, errors.New("key for repository not set")
} }
@ -612,7 +612,7 @@ func (s *Repo) Decrypt(ciphertext []byte) ([]byte, error) {
return crypto.Decrypt(s.key, nil, ciphertext) return crypto.Decrypt(s.key, nil, ciphertext)
} }
func (s *Repo) Encrypt(ciphertext, plaintext []byte) ([]byte, error) { func (s *Repository) Encrypt(ciphertext, plaintext []byte) ([]byte, error) {
if s.key == nil { if s.key == nil {
return nil, errors.New("key for repository not set") return nil, errors.New("key for repository not set")
} }
@ -620,16 +620,16 @@ func (s *Repo) Encrypt(ciphertext, plaintext []byte) ([]byte, error) {
return crypto.Encrypt(s.key, ciphertext, plaintext) return crypto.Encrypt(s.key, ciphertext, plaintext)
} }
func (s *Repo) Key() *crypto.Key { func (s *Repository) Key() *crypto.Key {
return s.key return s.key
} }
func (s *Repo) KeyName() string { func (s *Repository) KeyName() string {
return s.keyName return s.keyName
} }
// Count returns the number of blobs of a given type in the backend. // Count returns the number of blobs of a given type in the backend.
func (s *Repo) Count(t backend.Type) (n uint) { func (s *Repository) Count(t backend.Type) (n uint) {
for _ = range s.be.List(t, nil) { for _ = range s.be.List(t, nil) {
n++ n++
} }
@ -639,27 +639,27 @@ func (s *Repo) Count(t backend.Type) (n uint) {
// Proxy methods to backend // Proxy methods to backend
func (s *Repo) Get(t backend.Type, name string) (io.ReadCloser, error) { func (s *Repository) Get(t backend.Type, name string) (io.ReadCloser, error) {
return s.be.Get(t, name) return s.be.Get(t, name)
} }
func (s *Repo) List(t backend.Type, done <-chan struct{}) <-chan string { func (s *Repository) List(t backend.Type, done <-chan struct{}) <-chan string {
return s.be.List(t, done) return s.be.List(t, done)
} }
func (s *Repo) Test(t backend.Type, name string) (bool, error) { func (s *Repository) Test(t backend.Type, name string) (bool, error) {
return s.be.Test(t, name) return s.be.Test(t, name)
} }
func (s *Repo) Remove(t backend.Type, name string) error { func (s *Repository) Remove(t backend.Type, name string) error {
return s.be.Remove(t, name) return s.be.Remove(t, name)
} }
func (s *Repo) Close() error { func (s *Repository) Close() error {
return s.be.Close() return s.be.Close()
} }
func (s *Repo) Delete() error { func (s *Repository) Delete() error {
if b, ok := s.be.(backend.Deleter); ok { if b, ok := s.be.(backend.Deleter); ok {
return b.Delete() return b.Delete()
} }
@ -667,6 +667,6 @@ func (s *Repo) Delete() error {
return errors.New("Delete() called for backend that does not implement this method") return errors.New("Delete() called for backend that does not implement this method")
} }
func (s *Repo) Location() string { func (s *Repository) Location() string {
return s.be.Location() return s.be.Location()
} }

View file

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

View file

@ -7,14 +7,14 @@ import (
"syscall" "syscall"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
"github.com/juju/errors" "github.com/juju/errors"
) )
// Restorer is used to restore a snapshot to a directory. // Restorer is used to restore a snapshot to a directory.
type Restorer struct { type Restorer struct {
repo *repo.Repo repo *repository.Repository
sn *Snapshot sn *Snapshot
Error func(dir string, node *Node, err error) error 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 } var restorerAbortOnAllErrors = func(str string, node *Node, err error) error { return err }
// NewRestorer creates a restorer preloaded with the content from the snapshot id. // 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.Repository, id backend.ID) (*Restorer, error) {
r := &Restorer{repo: repo, Error: restorerAbortOnAllErrors} r := &Restorer{repo: repo, Error: restorerAbortOnAllErrors}
var err error var err error

View file

@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
) )
type Snapshot struct { type Snapshot struct {
@ -50,7 +50,7 @@ func NewSnapshot(paths []string) (*Snapshot, error) {
return sn, nil return sn, nil
} }
func LoadSnapshot(repo *repo.Repo, id backend.ID) (*Snapshot, error) { func LoadSnapshot(repo *repository.Repository, id backend.ID) (*Snapshot, error) {
sn := &Snapshot{id: id} sn := &Snapshot{id: id}
err := repo.LoadJSONUnpacked(backend.Snapshot, id, sn) err := repo.LoadJSONUnpacked(backend.Snapshot, id, sn)
if err != nil { if err != nil {

View file

@ -10,14 +10,14 @@ import (
"github.com/restic/restic" "github.com/restic/restic"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/backend/local" "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 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 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)") 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.Repository {
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-") tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
OK(t, err) OK(t, err)
@ -29,12 +29,12 @@ func SetupRepo(t testing.TB) *repo.Repo {
err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache")) err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache"))
OK(t, err) OK(t, err)
repo := repo.New(b) repo := repository.New(b)
OK(t, repo.Init(*TestPassword)) OK(t, repo.Init(*TestPassword))
return repo return repo
} }
func TeardownRepo(t testing.TB, repo *repo.Repo) { func TeardownRepo(t testing.TB, repo *repository.Repository) {
if !*TestCleanup { if !*TestCleanup {
l := repo.Backend().(*local.Local) l := repo.Backend().(*local.Local)
t.Logf("leaving local backend at %s\n", l.Location()) 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()) 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.Repository, path string, parent backend.ID) *restic.Snapshot {
arch := restic.NewArchiver(repo) arch := restic.NewArchiver(repo)
sn, _, err := arch.Snapshot(nil, []string{path}, parent) sn, _, err := arch.Snapshot(nil, []string{path}, parent)
OK(t, err) OK(t, err)

View file

@ -8,7 +8,7 @@ import (
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/pack" "github.com/restic/restic/pack"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
) )
type Tree struct { type Tree struct {
@ -30,7 +30,7 @@ func (t Tree) String() string {
return fmt.Sprintf("Tree<%d nodes>", len(t.Nodes)) return fmt.Sprintf("Tree<%d nodes>", len(t.Nodes))
} }
func LoadTree(repo *repo.Repo, id backend.ID) (*Tree, error) { func LoadTree(repo *repository.Repository, id backend.ID) (*Tree, error) {
tree := &Tree{} tree := &Tree{}
err := repo.LoadJSONPack(pack.Tree, id, tree) err := repo.LoadJSONPack(pack.Tree, id, tree)
if err != nil { if err != nil {

View file

@ -5,7 +5,7 @@ import (
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/debug" "github.com/restic/restic/debug"
"github.com/restic/restic/repo" "github.com/restic/restic/repository"
) )
type WalkTreeJob struct { type WalkTreeJob struct {
@ -16,7 +16,7 @@ type WalkTreeJob struct {
Tree *Tree Tree *Tree
} }
func walkTree(repo *repo.Repo, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { func walkTree(repo *repository.Repository, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
debug.Log("walkTree", "start on %q (%v)", path, treeID.Str()) debug.Log("walkTree", "start on %q (%v)", path, treeID.Str())
t, err := LoadTree(repo, treeID) 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 // 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 // file and directory it finds. When the channel done is closed, processing
// stops. // stops.
func WalkTree(repo *repo.Repo, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) { func WalkTree(repo *repository.Repository, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
debug.Log("WalkTree", "start on %v", id.Str()) debug.Log("WalkTree", "start on %v", id.Str())
walkTree(repo, "", id, done, jobCh) walkTree(repo, "", id, done, jobCh)
close(jobCh) close(jobCh)