Rename struct member FileType -> Type

This commit is contained in:
Alexander Neumann 2016-09-01 21:19:30 +02:00
parent 88d0f24ce7
commit 5e3a41dbd2
18 changed files with 78 additions and 78 deletions

View File

@ -98,7 +98,7 @@ func (cmd CmdCat) Execute(args []string) error {
return nil return nil
case "key": case "key":
h := restic.Handle{FileType: restic.KeyFile, Name: id.String()} h := restic.Handle{Type: restic.KeyFile, Name: id.String()}
buf, err := backend.LoadAll(repo.Backend(), h, nil) buf, err := backend.LoadAll(repo.Backend(), h, nil)
if err != nil { if err != nil {
return err return err
@ -149,7 +149,7 @@ func (cmd CmdCat) Execute(args []string) error {
switch tpe { switch tpe {
case "pack": case "pack":
h := restic.Handle{FileType: restic.DataFile, Name: id.String()} h := restic.Handle{Type: restic.DataFile, Name: id.String()}
buf, err := backend.LoadAll(repo.Backend(), h, nil) buf, err := backend.LoadAll(repo.Backend(), h, nil)
if err != nil { if err != nil {
return err return err

View File

@ -111,7 +111,7 @@ func (b *Local) Load(h restic.Handle, p []byte, off int64) (n int, err error) {
return 0, err return 0, err
} }
f, err := fs.Open(filename(b.p, h.FileType, h.Name)) f, err := fs.Open(filename(b.p, h.Type, h.Name))
if err != nil { if err != nil {
return 0, errors.Wrap(err, "Open") return 0, errors.Wrap(err, "Open")
} }
@ -183,7 +183,7 @@ func (b *Local) Save(h restic.Handle, p []byte) (err error) {
return err return err
} }
filename := filename(b.p, h.FileType, h.Name) filename := filename(b.p, h.Type, h.Name)
// test if new path already exists // test if new path already exists
if _, err := fs.Stat(filename); err == nil { if _, err := fs.Stat(filename); err == nil {
@ -191,7 +191,7 @@ func (b *Local) Save(h restic.Handle, p []byte) (err error) {
} }
// create directories if necessary, ignore errors // create directories if necessary, ignore errors
if h.FileType == restic.DataFile { if h.Type == restic.DataFile {
err = fs.MkdirAll(filepath.Dir(filename), backend.Modes.Dir) err = fs.MkdirAll(filepath.Dir(filename), backend.Modes.Dir)
if err != nil { if err != nil {
return errors.Wrap(err, "MkdirAll") return errors.Wrap(err, "MkdirAll")
@ -222,7 +222,7 @@ func (b *Local) Stat(h restic.Handle) (restic.FileInfo, error) {
return restic.FileInfo{}, err return restic.FileInfo{}, err
} }
fi, err := fs.Stat(filename(b.p, h.FileType, h.Name)) fi, err := fs.Stat(filename(b.p, h.Type, h.Name))
if err != nil { if err != nil {
return restic.FileInfo{}, errors.Wrap(err, "Stat") return restic.FileInfo{}, errors.Wrap(err, "Stat")
} }

View File

@ -61,17 +61,17 @@ func (be *MemoryBackend) Load(h restic.Handle, p []byte, off int64) (int, error)
be.m.Lock() be.m.Lock()
defer be.m.Unlock() defer be.m.Unlock()
if h.FileType == restic.ConfigFile { if h.Type == restic.ConfigFile {
h.Name = "" h.Name = ""
} }
debug.Log("MemoryBackend.Load", "get %v offset %v len %v", h, off, len(p)) debug.Log("MemoryBackend.Load", "get %v offset %v len %v", h, off, len(p))
if _, ok := be.data[entry{h.FileType, h.Name}]; !ok { if _, ok := be.data[entry{h.Type, h.Name}]; !ok {
return 0, errors.New("no such data") return 0, errors.New("no such data")
} }
buf := be.data[entry{h.FileType, h.Name}] buf := be.data[entry{h.Type, h.Name}]
switch { switch {
case off > int64(len(buf)): case off > int64(len(buf)):
return 0, errors.New("offset beyond end of file") return 0, errors.New("offset beyond end of file")
@ -101,18 +101,18 @@ func (be *MemoryBackend) Save(h restic.Handle, p []byte) error {
be.m.Lock() be.m.Lock()
defer be.m.Unlock() defer be.m.Unlock()
if h.FileType == restic.ConfigFile { if h.Type == restic.ConfigFile {
h.Name = "" h.Name = ""
} }
if _, ok := be.data[entry{h.FileType, h.Name}]; ok { if _, ok := be.data[entry{h.Type, h.Name}]; ok {
return errors.New("file already exists") return errors.New("file already exists")
} }
debug.Log("MemoryBackend.Save", "save %v bytes at %v", len(p), h) debug.Log("MemoryBackend.Save", "save %v bytes at %v", len(p), h)
buf := make([]byte, len(p)) buf := make([]byte, len(p))
copy(buf, p) copy(buf, p)
be.data[entry{h.FileType, h.Name}] = buf be.data[entry{h.Type, h.Name}] = buf
return nil return nil
} }
@ -126,13 +126,13 @@ func (be *MemoryBackend) Stat(h restic.Handle) (restic.FileInfo, error) {
return restic.FileInfo{}, err return restic.FileInfo{}, err
} }
if h.FileType == restic.ConfigFile { if h.Type == restic.ConfigFile {
h.Name = "" h.Name = ""
} }
debug.Log("MemoryBackend.Stat", "stat %v", h) debug.Log("MemoryBackend.Stat", "stat %v", h)
e, ok := be.data[entry{h.FileType, h.Name}] e, ok := be.data[entry{h.Type, h.Name}]
if !ok { if !ok {
return restic.FileInfo{}, errors.New("no such data") return restic.FileInfo{}, errors.New("no such data")
} }

View File

@ -24,7 +24,7 @@ func restPath(url *url.URL, h restic.Handle) string {
var dir string var dir string
switch h.FileType { switch h.Type {
case restic.ConfigFile: case restic.ConfigFile:
dir = "" dir = ""
h.Name = "config" h.Name = "config"
@ -39,7 +39,7 @@ func restPath(url *url.URL, h restic.Handle) string {
case restic.KeyFile: case restic.KeyFile:
dir = backend.Paths.Keys dir = backend.Paths.Keys
default: default:
dir = string(h.FileType) dir = string(h.Type)
} }
u.Path = path.Join(url.Path, dir, h.Name) u.Path = path.Join(url.Path, dir, h.Name)
@ -185,7 +185,7 @@ func (b *restBackend) Stat(h restic.Handle) (restic.FileInfo, error) {
// Test returns true if a blob of the given type and name exists in the backend. // Test returns true if a blob of the given type and name exists in the backend.
func (b *restBackend) Test(t restic.FileType, name string) (bool, error) { func (b *restBackend) Test(t restic.FileType, name string) (bool, error) {
_, err := b.Stat(restic.Handle{FileType: t, Name: name}) _, err := b.Stat(restic.Handle{Type: t, Name: name})
if err != nil { if err != nil {
return false, nil return false, nil
} }
@ -195,7 +195,7 @@ func (b *restBackend) Test(t restic.FileType, name string) (bool, error) {
// Remove removes the blob with the given name and type. // Remove removes the blob with the given name and type.
func (b *restBackend) Remove(t restic.FileType, name string) error { func (b *restBackend) Remove(t restic.FileType, name string) error {
h := restic.Handle{FileType: t, Name: name} h := restic.Handle{Type: t, Name: name}
if err := h.Valid(); err != nil { if err := h.Valid(); err != nil {
return err return err
} }
@ -225,7 +225,7 @@ func (b *restBackend) Remove(t restic.FileType, name string) error {
func (b *restBackend) List(t restic.FileType, done <-chan struct{}) <-chan string { func (b *restBackend) List(t restic.FileType, done <-chan struct{}) <-chan string {
ch := make(chan string) ch := make(chan string)
url := restPath(b.url, restic.Handle{FileType: t}) url := restPath(b.url, restic.Handle{Type: t})
if !strings.HasSuffix(url, "/") { if !strings.HasSuffix(url, "/") {
url += "/" url += "/"
} }

View File

@ -14,24 +14,24 @@ var restPathTests = []struct {
{ {
URL: parseURL("https://hostname.foo"), URL: parseURL("https://hostname.foo"),
Handle: restic.Handle{ Handle: restic.Handle{
FileType: restic.DataFile, Type: restic.DataFile,
Name: "foobar", Name: "foobar",
}, },
Result: "https://hostname.foo/data/foobar", Result: "https://hostname.foo/data/foobar",
}, },
{ {
URL: parseURL("https://hostname.foo:1234/prefix/repo"), URL: parseURL("https://hostname.foo:1234/prefix/repo"),
Handle: restic.Handle{ Handle: restic.Handle{
FileType: restic.LockFile, Type: restic.LockFile,
Name: "foobar", Name: "foobar",
}, },
Result: "https://hostname.foo:1234/prefix/repo/locks/foobar", Result: "https://hostname.foo:1234/prefix/repo/locks/foobar",
}, },
{ {
URL: parseURL("https://hostname.foo:1234/prefix/repo"), URL: parseURL("https://hostname.foo:1234/prefix/repo"),
Handle: restic.Handle{ Handle: restic.Handle{
FileType: restic.ConfigFile, Type: restic.ConfigFile,
Name: "foobar", Name: "foobar",
}, },
Result: "https://hostname.foo:1234/prefix/repo/config", Result: "https://hostname.foo:1234/prefix/repo/config",
}, },

View File

@ -85,7 +85,7 @@ func (be s3) Load(h restic.Handle, p []byte, off int64) (n int, err error) {
var obj *minio.Object var obj *minio.Object
debug.Log("s3.Load", "%v, offset %v, len %v", h, off, len(p)) debug.Log("s3.Load", "%v, offset %v, len %v", h, off, len(p))
path := be.s3path(h.FileType, h.Name) path := be.s3path(h.Type, h.Name)
<-be.connChan <-be.connChan
defer func() { defer func() {
@ -160,7 +160,7 @@ func (be s3) Save(h restic.Handle, p []byte) (err error) {
debug.Log("s3.Save", "%v with %d bytes", h, len(p)) debug.Log("s3.Save", "%v with %d bytes", h, len(p))
path := be.s3path(h.FileType, h.Name) path := be.s3path(h.Type, h.Name)
// Check key does not already exist // Check key does not already exist
_, err = be.client.StatObject(be.bucketname, path) _, err = be.client.StatObject(be.bucketname, path)
@ -186,7 +186,7 @@ func (be s3) Save(h restic.Handle, p []byte) (err error) {
func (be s3) Stat(h restic.Handle) (bi restic.FileInfo, err error) { func (be s3) Stat(h restic.Handle) (bi restic.FileInfo, err error) {
debug.Log("s3.Stat", "%v", h) debug.Log("s3.Stat", "%v", h)
path := be.s3path(h.FileType, h.Name) path := be.s3path(h.Type, h.Name)
var obj *minio.Object var obj *minio.Object
obj, err = be.client.GetObject(be.bucketname, path) obj, err = be.client.GetObject(be.bucketname, path)

View File

@ -338,7 +338,7 @@ func (r *SFTP) Load(h restic.Handle, p []byte, off int64) (n int, err error) {
return 0, err return 0, err
} }
f, err := r.c.Open(r.filename(h.FileType, h.Name)) f, err := r.c.Open(r.filename(h.Type, h.Name))
if err != nil { if err != nil {
return 0, errors.Wrap(err, "Open") return 0, errors.Wrap(err, "Open")
} }
@ -396,7 +396,7 @@ func (r *SFTP) Save(h restic.Handle, p []byte) (err error) {
return errors.Wrap(err, "Close") return errors.Wrap(err, "Close")
} }
err = r.renameFile(filename, h.FileType, h.Name) err = r.renameFile(filename, h.Type, h.Name)
debug.Log("sftp.Save", "save %v: rename %v: %v", debug.Log("sftp.Save", "save %v: rename %v: %v",
h, path.Base(filename), err) h, path.Base(filename), err)
return err return err
@ -413,7 +413,7 @@ func (r *SFTP) Stat(h restic.Handle) (restic.FileInfo, error) {
return restic.FileInfo{}, err return restic.FileInfo{}, err
} }
fi, err := r.c.Lstat(r.filename(h.FileType, h.Name)) fi, err := r.c.Lstat(r.filename(h.Type, h.Name))
if err != nil { if err != nil {
return restic.FileInfo{}, errors.Wrap(err, "Lstat") return restic.FileInfo{}, errors.Wrap(err, "Lstat")
} }

View File

@ -153,12 +153,12 @@ func TestConfig(t testing.TB) {
var testString = "Config" var testString = "Config"
// create config and read it back // create config and read it back
_, err := backend.LoadAll(b, restic.Handle{FileType: restic.ConfigFile}, nil) _, err := backend.LoadAll(b, restic.Handle{Type: restic.ConfigFile}, nil)
if err == nil { if err == nil {
t.Fatalf("did not get expected error for non-existing config") t.Fatalf("did not get expected error for non-existing config")
} }
err = b.Save(restic.Handle{FileType: restic.ConfigFile}, []byte(testString)) err = b.Save(restic.Handle{Type: restic.ConfigFile}, []byte(testString))
if err != nil { if err != nil {
t.Fatalf("Save() error: %v", err) t.Fatalf("Save() error: %v", err)
} }
@ -166,7 +166,7 @@ func TestConfig(t testing.TB) {
// try accessing the config with different names, should all return the // try accessing the config with different names, should all return the
// same config // same config
for _, name := range []string{"", "foo", "bar", "0000000000000000000000000000000000000000000000000000000000000000"} { for _, name := range []string{"", "foo", "bar", "0000000000000000000000000000000000000000000000000000000000000000"} {
h := restic.Handle{FileType: restic.ConfigFile, Name: name} h := restic.Handle{Type: restic.ConfigFile, Name: name}
buf, err := backend.LoadAll(b, h, nil) buf, err := backend.LoadAll(b, h, nil)
if err != nil { if err != nil {
t.Fatalf("unable to read config with name %q: %v", name, err) t.Fatalf("unable to read config with name %q: %v", name, err)
@ -188,7 +188,7 @@ func TestLoad(t testing.TB) {
t.Fatalf("Load() did not return an error for invalid handle") t.Fatalf("Load() did not return an error for invalid handle")
} }
_, err = b.Load(restic.Handle{FileType: restic.DataFile, Name: "foobar"}, nil, 0) _, err = b.Load(restic.Handle{Type: restic.DataFile, Name: "foobar"}, nil, 0)
if err == nil { if err == nil {
t.Fatalf("Load() did not return an error for non-existing blob") t.Fatalf("Load() did not return an error for non-existing blob")
} }
@ -198,7 +198,7 @@ func TestLoad(t testing.TB) {
data := Random(23, length) data := Random(23, length)
id := restic.Hash(data) id := restic.Hash(data)
handle := restic.Handle{FileType: restic.DataFile, Name: id.String()} handle := restic.Handle{Type: restic.DataFile, Name: id.String()}
err = b.Save(handle, data) err = b.Save(handle, data)
if err != nil { if err != nil {
t.Fatalf("Save() error: %v", err) t.Fatalf("Save() error: %v", err)
@ -323,7 +323,7 @@ func TestLoadNegativeOffset(t testing.TB) {
data := Random(23, length) data := Random(23, length)
id := restic.Hash(data) id := restic.Hash(data)
handle := restic.Handle{FileType: restic.DataFile, Name: id.String()} handle := restic.Handle{Type: restic.DataFile, Name: id.String()}
err := b.Save(handle, data) err := b.Save(handle, data)
if err != nil { if err != nil {
t.Fatalf("Save() error: %v", err) t.Fatalf("Save() error: %v", err)
@ -382,8 +382,8 @@ func TestSave(t testing.TB) {
copy(id[:], data) copy(id[:], data)
h := restic.Handle{ h := restic.Handle{
FileType: restic.DataFile, Type: restic.DataFile,
Name: fmt.Sprintf("%s-%d", id, i), Name: fmt.Sprintf("%s-%d", id, i),
} }
err := b.Save(h, data) err := b.Save(h, data)
OK(t, err) OK(t, err)
@ -405,7 +405,7 @@ func TestSave(t testing.TB) {
t.Fatalf("Stat() returned different size, want %q, got %d", len(data), fi.Size) t.Fatalf("Stat() returned different size, want %q, got %d", len(data), fi.Size)
} }
err = b.Remove(h.FileType, h.Name) err = b.Remove(h.Type, h.Name)
if err != nil { if err != nil {
t.Fatalf("error removing item: %v", err) t.Fatalf("error removing item: %v", err)
} }
@ -430,7 +430,7 @@ func TestSaveFilenames(t testing.TB) {
defer close(t) defer close(t)
for i, test := range filenameTests { for i, test := range filenameTests {
h := restic.Handle{Name: test.name, FileType: restic.DataFile} h := restic.Handle{Name: test.name, Type: restic.DataFile}
err := b.Save(h, []byte(test.data)) err := b.Save(h, []byte(test.data))
if err != nil { if err != nil {
t.Errorf("test %d failed: Save() returned %v", i, err) t.Errorf("test %d failed: Save() returned %v", i, err)
@ -447,7 +447,7 @@ func TestSaveFilenames(t testing.TB) {
t.Errorf("test %d: returned wrong bytes", i) t.Errorf("test %d: returned wrong bytes", i)
} }
err = b.Remove(h.FileType, h.Name) err = b.Remove(h.Type, h.Name)
if err != nil { if err != nil {
t.Errorf("test %d failed: Remove() returned %v", i, err) t.Errorf("test %d failed: Remove() returned %v", i, err)
continue continue
@ -467,7 +467,7 @@ var testStrings = []struct {
func store(t testing.TB, b restic.Backend, tpe restic.FileType, data []byte) { func store(t testing.TB, b restic.Backend, tpe restic.FileType, data []byte) {
id := restic.Hash(data) id := restic.Hash(data)
err := b.Save(restic.Handle{Name: id.String(), FileType: tpe}, data) err := b.Save(restic.Handle{Name: id.String(), Type: tpe}, data)
OK(t, err) OK(t, err)
} }
@ -499,7 +499,7 @@ func TestBackend(t testing.TB) {
Assert(t, !ret, "blob was found to exist before creating") Assert(t, !ret, "blob was found to exist before creating")
// try to stat a not existing blob // try to stat a not existing blob
h := restic.Handle{FileType: tpe, Name: id.String()} h := restic.Handle{Type: tpe, Name: id.String()}
_, err = b.Stat(h) _, err = b.Stat(h)
Assert(t, err != nil, "blob data could be extracted before creation") Assert(t, err != nil, "blob data could be extracted before creation")
@ -518,7 +518,7 @@ func TestBackend(t testing.TB) {
store(t, b, tpe, []byte(test.data)) store(t, b, tpe, []byte(test.data))
// test Load() // test Load()
h := restic.Handle{FileType: tpe, Name: test.id} h := restic.Handle{Type: tpe, Name: test.id}
buf, err := backend.LoadAll(b, h, nil) buf, err := backend.LoadAll(b, h, nil)
OK(t, err) OK(t, err)
Equals(t, test.data, string(buf)) Equals(t, test.data, string(buf))
@ -539,7 +539,7 @@ func TestBackend(t testing.TB) {
test := testStrings[0] test := testStrings[0]
// create blob // create blob
err := b.Save(restic.Handle{FileType: tpe, Name: test.id}, []byte(test.data)) err := b.Save(restic.Handle{Type: tpe, Name: test.id}, []byte(test.data))
Assert(t, err != nil, "expected error, got %v", err) Assert(t, err != nil, "expected error, got %v", err)
// remove and recreate // remove and recreate
@ -552,7 +552,7 @@ func TestBackend(t testing.TB) {
Assert(t, ok == false, "removed blob still present") Assert(t, ok == false, "removed blob still present")
// create blob // create blob
err = b.Save(restic.Handle{FileType: tpe, Name: test.id}, []byte(test.data)) err = b.Save(restic.Handle{Type: tpe, Name: test.id}, []byte(test.data))
OK(t, err) OK(t, err)
// list items // list items

View File

@ -21,10 +21,10 @@ func TestLoadAll(t *testing.T) {
data := Random(23+i, rand.Intn(MiB)+500*KiB) data := Random(23+i, rand.Intn(MiB)+500*KiB)
id := restic.Hash(data) id := restic.Hash(data)
err := b.Save(restic.Handle{Name: id.String(), FileType: restic.DataFile}, data) err := b.Save(restic.Handle{Name: id.String(), Type: restic.DataFile}, data)
OK(t, err) OK(t, err)
buf, err := backend.LoadAll(b, restic.Handle{FileType: restic.DataFile, Name: id.String()}, nil) buf, err := backend.LoadAll(b, restic.Handle{Type: restic.DataFile, Name: id.String()}, nil)
OK(t, err) OK(t, err)
if len(buf) != len(data) { if len(buf) != len(data) {
@ -46,11 +46,11 @@ func TestLoadSmallBuffer(t *testing.T) {
data := Random(23+i, rand.Intn(MiB)+500*KiB) data := Random(23+i, rand.Intn(MiB)+500*KiB)
id := restic.Hash(data) id := restic.Hash(data)
err := b.Save(restic.Handle{Name: id.String(), FileType: restic.DataFile}, data) err := b.Save(restic.Handle{Name: id.String(), Type: restic.DataFile}, data)
OK(t, err) OK(t, err)
buf := make([]byte, len(data)-23) buf := make([]byte, len(data)-23)
buf, err = backend.LoadAll(b, restic.Handle{FileType: restic.DataFile, Name: id.String()}, buf) buf, err = backend.LoadAll(b, restic.Handle{Type: restic.DataFile, Name: id.String()}, buf)
OK(t, err) OK(t, err)
if len(buf) != len(data) { if len(buf) != len(data) {
@ -72,11 +72,11 @@ func TestLoadLargeBuffer(t *testing.T) {
data := Random(23+i, rand.Intn(MiB)+500*KiB) data := Random(23+i, rand.Intn(MiB)+500*KiB)
id := restic.Hash(data) id := restic.Hash(data)
err := b.Save(restic.Handle{Name: id.String(), FileType: restic.DataFile}, data) err := b.Save(restic.Handle{Name: id.String(), Type: restic.DataFile}, data)
OK(t, err) OK(t, err)
buf := make([]byte, len(data)+100) buf := make([]byte, len(data)+100)
buf, err = backend.LoadAll(b, restic.Handle{FileType: restic.DataFile, Name: id.String()}, buf) buf, err = backend.LoadAll(b, restic.Handle{Type: restic.DataFile, Name: id.String()}, buf)
OK(t, err) OK(t, err)
if len(buf) != len(data) { if len(buf) != len(data) {

View File

@ -662,7 +662,7 @@ func (c *Checker) CountPacks() uint64 {
// checkPack reads a pack and checks the integrity of all blobs. // checkPack reads a pack and checks the integrity of all blobs.
func checkPack(r restic.Repository, id restic.ID) error { func checkPack(r restic.Repository, id restic.ID) error {
debug.Log("Checker.checkPack", "checking pack %v", id.Str()) debug.Log("Checker.checkPack", "checking pack %v", id.Str())
h := restic.Handle{FileType: restic.DataFile, Name: id.String()} h := restic.Handle{Type: restic.DataFile, Name: id.String()}
buf, err := backend.LoadAll(r.Backend(), h, nil) buf, err := backend.LoadAll(r.Backend(), h, nil)
if err != nil { if err != nil {
return err return err

View File

@ -21,8 +21,8 @@ const (
// Handle is used to store and access data in a backend. // Handle is used to store and access data in a backend.
type Handle struct { type Handle struct {
FileType FileType Type FileType
Name string Name string
} }
func (h Handle) String() string { func (h Handle) String() string {
@ -30,16 +30,16 @@ func (h Handle) String() string {
if len(name) > 10 { if len(name) > 10 {
name = name[:10] name = name[:10]
} }
return fmt.Sprintf("<%s/%s>", h.FileType, name) return fmt.Sprintf("<%s/%s>", h.Type, name)
} }
// Valid returns an error if h is not valid. // Valid returns an error if h is not valid.
func (h Handle) Valid() error { func (h Handle) Valid() error {
if h.FileType == "" { if h.Type == "" {
return errors.New("type is empty") return errors.New("type is empty")
} }
switch h.FileType { switch h.Type {
case DataFile: case DataFile:
case KeyFile: case KeyFile:
case LockFile: case LockFile:
@ -47,10 +47,10 @@ func (h Handle) Valid() error {
case IndexFile: case IndexFile:
case ConfigFile: case ConfigFile:
default: default:
return errors.Errorf("invalid Type %q", h.FileType) return errors.Errorf("invalid Type %q", h.Type)
} }
if h.FileType == ConfigFile { if h.Type == ConfigFile {
return nil return nil
} }

View File

@ -7,11 +7,11 @@ var handleTests = []struct {
valid bool valid bool
}{ }{
{Handle{Name: "foo"}, false}, {Handle{Name: "foo"}, false},
{Handle{FileType: "foobar"}, false}, {Handle{Type: "foobar"}, false},
{Handle{FileType: ConfigFile, Name: ""}, true}, {Handle{Type: ConfigFile, Name: ""}, true},
{Handle{FileType: DataFile, Name: ""}, false}, {Handle{Type: DataFile, Name: ""}, false},
{Handle{FileType: "", Name: "x"}, false}, {Handle{Type: "", Name: "x"}, false},
{Handle{FileType: LockFile, Name: "010203040506"}, true}, {Handle{Type: LockFile, Name: "010203040506"}, true},
} }
func TestHandleValid(t *testing.T) { func TestHandleValid(t *testing.T) {

View File

@ -126,7 +126,7 @@ func TestUnpackReadSeeker(t *testing.T) {
b := mem.New() b := mem.New()
id := restic.Hash(packData) id := restic.Hash(packData)
handle := restic.Handle{FileType: restic.DataFile, Name: id.String()} handle := restic.Handle{Type: restic.DataFile, Name: id.String()}
OK(t, b.Save(handle, packData)) OK(t, b.Save(handle, packData))
verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize) verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize)
} }
@ -139,7 +139,7 @@ func TestShortPack(t *testing.T) {
b := mem.New() b := mem.New()
id := restic.Hash(packData) id := restic.Hash(packData)
handle := restic.Handle{FileType: restic.DataFile, Name: id.String()} handle := restic.Handle{Type: restic.DataFile, Name: id.String()}
OK(t, b.Save(handle, packData)) OK(t, b.Save(handle, packData))
verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize) verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize)
} }

View File

@ -143,7 +143,7 @@ func SearchKey(s *Repository, password string, maxKeys int) (*Key, error) {
// LoadKey loads a key from the backend. // LoadKey loads a key from the backend.
func LoadKey(s *Repository, name string) (k *Key, err error) { func LoadKey(s *Repository, name string) (k *Key, err error) {
h := restic.Handle{FileType: restic.KeyFile, Name: name} h := restic.Handle{Type: restic.KeyFile, Name: name}
data, err := backend.LoadAll(s.be, h, nil) data, err := backend.LoadAll(s.be, h, nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -226,8 +226,8 @@ func AddKey(s *Repository, password string, template *crypto.Key) (*Key, error)
// store in repository and return // store in repository and return
h := restic.Handle{ h := restic.Handle{
FileType: restic.KeyFile, Type: restic.KeyFile,
Name: restic.Hash(buf).String(), Name: restic.Hash(buf).String(),
} }
err = s.be.Save(h, buf) err = s.be.Save(h, buf)

View File

@ -115,7 +115,7 @@ func (r *Repository) savePacker(p *pack.Packer) error {
} }
id := restic.Hash(data) id := restic.Hash(data)
h := restic.Handle{FileType: restic.DataFile, Name: id.String()} h := restic.Handle{Type: restic.DataFile, Name: id.String()}
err = r.be.Save(h, data) err = r.be.Save(h, data)
if err != nil { if err != nil {

View File

@ -63,7 +63,7 @@ func saveFile(t testing.TB, be Saver, filename string, n int) {
t.Fatal(err) t.Fatal(err)
} }
h := restic.Handle{FileType: restic.DataFile, Name: restic.Hash(data).String()} h := restic.Handle{Type: restic.DataFile, Name: restic.Hash(data).String()}
err = be.Save(h, data) err = be.Save(h, data)
if err != nil { if err != nil {

View File

@ -21,7 +21,7 @@ func Repack(repo *Repository, packs restic.IDSet, keepBlobs restic.BlobSet) (err
buf := make([]byte, 0, maxPackSize) buf := make([]byte, 0, maxPackSize)
for packID := range packs { for packID := range packs {
// load the complete pack // load the complete pack
h := restic.Handle{FileType: restic.DataFile, Name: packID.String()} h := restic.Handle{Type: restic.DataFile, Name: packID.String()}
l, err := repo.Backend().Load(h, buf[:cap(buf)], 0) l, err := repo.Backend().Load(h, buf[:cap(buf)], 0)
if errors.Cause(err) == io.ErrUnexpectedEOF { if errors.Cause(err) == io.ErrUnexpectedEOF {

View File

@ -61,7 +61,7 @@ func (r *Repository) PrefixLength(t restic.FileType) (int, error) {
func (r *Repository) LoadAndDecrypt(t restic.FileType, id restic.ID) ([]byte, error) { func (r *Repository) LoadAndDecrypt(t restic.FileType, id restic.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())
h := restic.Handle{FileType: t, Name: id.String()} h := restic.Handle{Type: t, Name: id.String()}
buf, err := backend.LoadAll(r.be, h, nil) buf, err := backend.LoadAll(r.be, h, nil)
if err != nil { if err != nil {
debug.Log("Repo.Load", "error loading %v: %v", id.Str(), err) debug.Log("Repo.Load", "error loading %v: %v", id.Str(), err)
@ -117,7 +117,7 @@ func (r *Repository) LoadBlob(id restic.ID, t restic.BlobType, plaintextBuf []by
} }
// load blob from pack // load blob from pack
h := restic.Handle{FileType: restic.DataFile, Name: blob.PackID.String()} h := restic.Handle{Type: restic.DataFile, Name: blob.PackID.String()}
ciphertextBuf := make([]byte, blob.Length) ciphertextBuf := make([]byte, blob.Length)
n, err := r.be.Load(h, ciphertextBuf, int64(blob.Offset)) n, err := r.be.Load(h, ciphertextBuf, int64(blob.Offset))
if err != nil { if err != nil {
@ -279,7 +279,7 @@ func (r *Repository) SaveUnpacked(t restic.FileType, p []byte) (id restic.ID, er
} }
id = restic.Hash(ciphertext) id = restic.Hash(ciphertext)
h := restic.Handle{FileType: t, Name: id.String()} h := restic.Handle{Type: t, Name: id.String()}
err = r.be.Save(h, ciphertext) err = r.be.Save(h, ciphertext)
if err != nil { if err != nil {
@ -560,7 +560,7 @@ func (r *Repository) List(t restic.FileType, done <-chan struct{}) <-chan restic
// ListPack returns the list of blobs saved in the pack id and the length of // ListPack returns the list of blobs saved in the pack id and the length of
// the file as stored in the backend. // the file as stored in the backend.
func (r *Repository) ListPack(id restic.ID) ([]restic.Blob, int64, error) { func (r *Repository) ListPack(id restic.ID) ([]restic.Blob, int64, error) {
h := restic.Handle{FileType: restic.DataFile, Name: id.String()} h := restic.Handle{Type: restic.DataFile, Name: id.String()}
blobInfo, err := r.Backend().Stat(h) blobInfo, err := r.Backend().Stat(h)
if err != nil { if err != nil {