Rename struct member FileType -> Type
This commit is contained in:
parent
88d0f24ce7
commit
5e3a41dbd2
18 changed files with 78 additions and 78 deletions
|
@ -98,7 +98,7 @@ func (cmd CmdCat) Execute(args []string) error {
|
|||
|
||||
return nil
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -149,7 +149,7 @@ func (cmd CmdCat) Execute(args []string) error {
|
|||
|
||||
switch tpe {
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -111,7 +111,7 @@ func (b *Local) Load(h restic.Handle, p []byte, off int64) (n int, err error) {
|
|||
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 {
|
||||
return 0, errors.Wrap(err, "Open")
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ func (b *Local) Save(h restic.Handle, p []byte) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
filename := filename(b.p, h.FileType, h.Name)
|
||||
filename := filename(b.p, h.Type, h.Name)
|
||||
|
||||
// test if new path already exists
|
||||
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
|
||||
if h.FileType == restic.DataFile {
|
||||
if h.Type == restic.DataFile {
|
||||
err = fs.MkdirAll(filepath.Dir(filename), backend.Modes.Dir)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "MkdirAll")
|
||||
|
@ -222,7 +222,7 @@ func (b *Local) Stat(h restic.Handle) (restic.FileInfo, error) {
|
|||
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 {
|
||||
return restic.FileInfo{}, errors.Wrap(err, "Stat")
|
||||
}
|
||||
|
|
|
@ -61,17 +61,17 @@ func (be *MemoryBackend) Load(h restic.Handle, p []byte, off int64) (int, error)
|
|||
be.m.Lock()
|
||||
defer be.m.Unlock()
|
||||
|
||||
if h.FileType == restic.ConfigFile {
|
||||
if h.Type == restic.ConfigFile {
|
||||
h.Name = ""
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
buf := be.data[entry{h.FileType, h.Name}]
|
||||
buf := be.data[entry{h.Type, h.Name}]
|
||||
switch {
|
||||
case off > int64(len(buf)):
|
||||
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()
|
||||
defer be.m.Unlock()
|
||||
|
||||
if h.FileType == restic.ConfigFile {
|
||||
if h.Type == restic.ConfigFile {
|
||||
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")
|
||||
}
|
||||
|
||||
debug.Log("MemoryBackend.Save", "save %v bytes at %v", len(p), h)
|
||||
buf := make([]byte, len(p))
|
||||
copy(buf, p)
|
||||
be.data[entry{h.FileType, h.Name}] = buf
|
||||
be.data[entry{h.Type, h.Name}] = buf
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -126,13 +126,13 @@ func (be *MemoryBackend) Stat(h restic.Handle) (restic.FileInfo, error) {
|
|||
return restic.FileInfo{}, err
|
||||
}
|
||||
|
||||
if h.FileType == restic.ConfigFile {
|
||||
if h.Type == restic.ConfigFile {
|
||||
h.Name = ""
|
||||
}
|
||||
|
||||
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 {
|
||||
return restic.FileInfo{}, errors.New("no such data")
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func restPath(url *url.URL, h restic.Handle) string {
|
|||
|
||||
var dir string
|
||||
|
||||
switch h.FileType {
|
||||
switch h.Type {
|
||||
case restic.ConfigFile:
|
||||
dir = ""
|
||||
h.Name = "config"
|
||||
|
@ -39,7 +39,7 @@ func restPath(url *url.URL, h restic.Handle) string {
|
|||
case restic.KeyFile:
|
||||
dir = backend.Paths.Keys
|
||||
default:
|
||||
dir = string(h.FileType)
|
||||
dir = string(h.Type)
|
||||
}
|
||||
|
||||
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.
|
||||
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 {
|
||||
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.
|
||||
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 {
|
||||
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 {
|
||||
ch := make(chan string)
|
||||
|
||||
url := restPath(b.url, restic.Handle{FileType: t})
|
||||
url := restPath(b.url, restic.Handle{Type: t})
|
||||
if !strings.HasSuffix(url, "/") {
|
||||
url += "/"
|
||||
}
|
||||
|
|
|
@ -14,24 +14,24 @@ var restPathTests = []struct {
|
|||
{
|
||||
URL: parseURL("https://hostname.foo"),
|
||||
Handle: restic.Handle{
|
||||
FileType: restic.DataFile,
|
||||
Name: "foobar",
|
||||
Type: restic.DataFile,
|
||||
Name: "foobar",
|
||||
},
|
||||
Result: "https://hostname.foo/data/foobar",
|
||||
},
|
||||
{
|
||||
URL: parseURL("https://hostname.foo:1234/prefix/repo"),
|
||||
Handle: restic.Handle{
|
||||
FileType: restic.LockFile,
|
||||
Name: "foobar",
|
||||
Type: restic.LockFile,
|
||||
Name: "foobar",
|
||||
},
|
||||
Result: "https://hostname.foo:1234/prefix/repo/locks/foobar",
|
||||
},
|
||||
{
|
||||
URL: parseURL("https://hostname.foo:1234/prefix/repo"),
|
||||
Handle: restic.Handle{
|
||||
FileType: restic.ConfigFile,
|
||||
Name: "foobar",
|
||||
Type: restic.ConfigFile,
|
||||
Name: "foobar",
|
||||
},
|
||||
Result: "https://hostname.foo:1234/prefix/repo/config",
|
||||
},
|
||||
|
|
|
@ -85,7 +85,7 @@ func (be s3) Load(h restic.Handle, p []byte, off int64) (n int, err error) {
|
|||
var obj *minio.Object
|
||||
|
||||
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
|
||||
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))
|
||||
|
||||
path := be.s3path(h.FileType, h.Name)
|
||||
path := be.s3path(h.Type, h.Name)
|
||||
|
||||
// Check key does not already exist
|
||||
_, 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) {
|
||||
debug.Log("s3.Stat", "%v", h)
|
||||
|
||||
path := be.s3path(h.FileType, h.Name)
|
||||
path := be.s3path(h.Type, h.Name)
|
||||
var obj *minio.Object
|
||||
|
||||
obj, err = be.client.GetObject(be.bucketname, path)
|
||||
|
|
|
@ -338,7 +338,7 @@ func (r *SFTP) Load(h restic.Handle, p []byte, off int64) (n int, err error) {
|
|||
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 {
|
||||
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")
|
||||
}
|
||||
|
||||
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",
|
||||
h, path.Base(filename), err)
|
||||
return err
|
||||
|
@ -413,7 +413,7 @@ func (r *SFTP) Stat(h restic.Handle) (restic.FileInfo, error) {
|
|||
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 {
|
||||
return restic.FileInfo{}, errors.Wrap(err, "Lstat")
|
||||
}
|
||||
|
|
|
@ -153,12 +153,12 @@ func TestConfig(t testing.TB) {
|
|||
var testString = "Config"
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
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
|
||||
// same config
|
||||
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)
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
|
||||
_, 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 {
|
||||
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)
|
||||
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)
|
||||
if err != nil {
|
||||
t.Fatalf("Save() error: %v", err)
|
||||
|
@ -323,7 +323,7 @@ func TestLoadNegativeOffset(t testing.TB) {
|
|||
data := Random(23, length)
|
||||
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)
|
||||
if err != nil {
|
||||
t.Fatalf("Save() error: %v", err)
|
||||
|
@ -382,8 +382,8 @@ func TestSave(t testing.TB) {
|
|||
copy(id[:], data)
|
||||
|
||||
h := restic.Handle{
|
||||
FileType: restic.DataFile,
|
||||
Name: fmt.Sprintf("%s-%d", id, i),
|
||||
Type: restic.DataFile,
|
||||
Name: fmt.Sprintf("%s-%d", id, i),
|
||||
}
|
||||
err := b.Save(h, data)
|
||||
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)
|
||||
}
|
||||
|
||||
err = b.Remove(h.FileType, h.Name)
|
||||
err = b.Remove(h.Type, h.Name)
|
||||
if err != nil {
|
||||
t.Fatalf("error removing item: %v", err)
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ func TestSaveFilenames(t testing.TB) {
|
|||
defer close(t)
|
||||
|
||||
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))
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
err = b.Remove(h.FileType, h.Name)
|
||||
err = b.Remove(h.Type, h.Name)
|
||||
if err != nil {
|
||||
t.Errorf("test %d failed: Remove() returned %v", i, err)
|
||||
continue
|
||||
|
@ -467,7 +467,7 @@ var testStrings = []struct {
|
|||
|
||||
func store(t testing.TB, b restic.Backend, tpe restic.FileType, data []byte) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -499,7 +499,7 @@ func TestBackend(t testing.TB) {
|
|||
Assert(t, !ret, "blob was found to exist before creating")
|
||||
|
||||
// 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)
|
||||
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))
|
||||
|
||||
// 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)
|
||||
OK(t, err)
|
||||
Equals(t, test.data, string(buf))
|
||||
|
@ -539,7 +539,7 @@ func TestBackend(t testing.TB) {
|
|||
test := testStrings[0]
|
||||
|
||||
// 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)
|
||||
|
||||
// remove and recreate
|
||||
|
@ -552,7 +552,7 @@ func TestBackend(t testing.TB) {
|
|||
Assert(t, ok == false, "removed blob still present")
|
||||
|
||||
// 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)
|
||||
|
||||
// list items
|
||||
|
|
|
@ -21,10 +21,10 @@ func TestLoadAll(t *testing.T) {
|
|||
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
if len(buf) != len(data) {
|
||||
|
@ -46,11 +46,11 @@ func TestLoadSmallBuffer(t *testing.T) {
|
|||
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
if len(buf) != len(data) {
|
||||
|
@ -72,11 +72,11 @@ func TestLoadLargeBuffer(t *testing.T) {
|
|||
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
if len(buf) != len(data) {
|
||||
|
|
|
@ -662,7 +662,7 @@ func (c *Checker) CountPacks() uint64 {
|
|||
// checkPack reads a pack and checks the integrity of all blobs.
|
||||
func checkPack(r restic.Repository, id restic.ID) error {
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -21,8 +21,8 @@ const (
|
|||
|
||||
// Handle is used to store and access data in a backend.
|
||||
type Handle struct {
|
||||
FileType FileType
|
||||
Name string
|
||||
Type FileType
|
||||
Name string
|
||||
}
|
||||
|
||||
func (h Handle) String() string {
|
||||
|
@ -30,16 +30,16 @@ func (h Handle) String() string {
|
|||
if len(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.
|
||||
func (h Handle) Valid() error {
|
||||
if h.FileType == "" {
|
||||
if h.Type == "" {
|
||||
return errors.New("type is empty")
|
||||
}
|
||||
|
||||
switch h.FileType {
|
||||
switch h.Type {
|
||||
case DataFile:
|
||||
case KeyFile:
|
||||
case LockFile:
|
||||
|
@ -47,10 +47,10 @@ func (h Handle) Valid() error {
|
|||
case IndexFile:
|
||||
case ConfigFile:
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@ var handleTests = []struct {
|
|||
valid bool
|
||||
}{
|
||||
{Handle{Name: "foo"}, false},
|
||||
{Handle{FileType: "foobar"}, false},
|
||||
{Handle{FileType: ConfigFile, Name: ""}, true},
|
||||
{Handle{FileType: DataFile, Name: ""}, false},
|
||||
{Handle{FileType: "", Name: "x"}, false},
|
||||
{Handle{FileType: LockFile, Name: "010203040506"}, true},
|
||||
{Handle{Type: "foobar"}, false},
|
||||
{Handle{Type: ConfigFile, Name: ""}, true},
|
||||
{Handle{Type: DataFile, Name: ""}, false},
|
||||
{Handle{Type: "", Name: "x"}, false},
|
||||
{Handle{Type: LockFile, Name: "010203040506"}, true},
|
||||
}
|
||||
|
||||
func TestHandleValid(t *testing.T) {
|
||||
|
|
|
@ -126,7 +126,7 @@ func TestUnpackReadSeeker(t *testing.T) {
|
|||
b := mem.New()
|
||||
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))
|
||||
verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize)
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func TestShortPack(t *testing.T) {
|
|||
b := mem.New()
|
||||
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))
|
||||
verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize)
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ func SearchKey(s *Repository, password string, maxKeys int) (*Key, error) {
|
|||
|
||||
// LoadKey loads a key from the backend.
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -226,8 +226,8 @@ func AddKey(s *Repository, password string, template *crypto.Key) (*Key, error)
|
|||
|
||||
// store in repository and return
|
||||
h := restic.Handle{
|
||||
FileType: restic.KeyFile,
|
||||
Name: restic.Hash(buf).String(),
|
||||
Type: restic.KeyFile,
|
||||
Name: restic.Hash(buf).String(),
|
||||
}
|
||||
|
||||
err = s.be.Save(h, buf)
|
||||
|
|
|
@ -115,7 +115,7 @@ func (r *Repository) savePacker(p *pack.Packer) error {
|
|||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
|
|
|
@ -63,7 +63,7 @@ func saveFile(t testing.TB, be Saver, filename string, n int) {
|
|||
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)
|
||||
if err != nil {
|
||||
|
|
|
@ -21,7 +21,7 @@ func Repack(repo *Repository, packs restic.IDSet, keepBlobs restic.BlobSet) (err
|
|||
buf := make([]byte, 0, maxPackSize)
|
||||
for packID := range packs {
|
||||
// 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)
|
||||
if errors.Cause(err) == io.ErrUnexpectedEOF {
|
||||
|
|
|
@ -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) {
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
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)
|
||||
n, err := r.be.Load(h, ciphertextBuf, int64(blob.Offset))
|
||||
if err != nil {
|
||||
|
@ -279,7 +279,7 @@ func (r *Repository) SaveUnpacked(t restic.FileType, p []byte) (id restic.ID, er
|
|||
}
|
||||
|
||||
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)
|
||||
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
|
||||
// the file as stored in the backend.
|
||||
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)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue