forked from TrueCloudLab/restic
Rename package 'server' to 'repo'
This commit is contained in:
parent
1d37fe3f97
commit
8be9e95d20
23 changed files with 63 additions and 63 deletions
|
@ -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),
|
||||
|
|
6
cache.go
6
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
8
node.go
8
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()
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package server
|
||||
package repo
|
||||
|
||||
import (
|
||||
"bytes"
|
2
repo/doc.go
Normal file
2
repo/doc.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package repo implements a restic repository on top of a backend.
|
||||
package repo
|
|
@ -1,4 +1,4 @@
|
|||
package server
|
||||
package repo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -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 {
|
|
@ -1,4 +1,4 @@
|
|||
package server
|
||||
package repo
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
|
@ -1,4 +1,4 @@
|
|||
package server
|
||||
package repo
|
||||
|
||||
import (
|
||||
"sync"
|
|
@ -1,4 +1,4 @@
|
|||
package server
|
||||
package repo
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package server_test
|
||||
package repo_test
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -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
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
// Package server implements a restic repository on top of a backend.
|
||||
package server
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
4
tree.go
4
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 {
|
||||
|
|
6
walk.go
6
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)
|
||||
|
|
Loading…
Reference in a new issue