mirror of
https://github.com/octoleo/restic.git
synced 2024-12-01 17:23:57 +00:00
Fix inconsistency of saving/loading config file
Fix saving/loading config file: Always set ID to a zero ID.
This commit is contained in:
parent
dd7b4f54f5
commit
d3c59d18e5
@ -82,6 +82,10 @@ func (r *Repository) LoadAndDecrypt(ctx context.Context, buf []byte, t restic.Fi
|
|||||||
|
|
||||||
debug.Log("load %v with id %v", t, id)
|
debug.Log("load %v with id %v", t, id)
|
||||||
|
|
||||||
|
if t == restic.ConfigFile {
|
||||||
|
id = restic.ID{}
|
||||||
|
}
|
||||||
|
|
||||||
h := restic.Handle{Type: t, Name: id.String()}
|
h := restic.Handle{Type: t, Name: id.String()}
|
||||||
err := r.be.Load(ctx, h, 0, 0, func(rd io.Reader) error {
|
err := r.be.Load(ctx, h, 0, 0, func(rd io.Reader) error {
|
||||||
// make sure this call is idempotent, in case an error occurs
|
// make sure this call is idempotent, in case an error occurs
|
||||||
@ -295,7 +299,11 @@ func (r *Repository) SaveUnpacked(ctx context.Context, t restic.FileType, p []by
|
|||||||
|
|
||||||
ciphertext = r.key.Seal(ciphertext, nonce, p, nil)
|
ciphertext = r.key.Seal(ciphertext, nonce, p, nil)
|
||||||
|
|
||||||
|
if t == restic.ConfigFile {
|
||||||
|
id = restic.ID{}
|
||||||
|
} else {
|
||||||
id = restic.Hash(ciphertext)
|
id = restic.Hash(ciphertext)
|
||||||
|
}
|
||||||
h := restic.Handle{Type: t, Name: id.String()}
|
h := restic.Handle{Type: t, Name: id.String()}
|
||||||
|
|
||||||
err = r.be.Save(ctx, h, restic.NewByteReader(ciphertext))
|
err = r.be.Save(ctx, h, restic.NewByteReader(ciphertext))
|
||||||
|
@ -274,6 +274,14 @@ func TestLoadJSONUnpacked(t *testing.T) {
|
|||||||
|
|
||||||
rtest.Equals(t, sn.Hostname, sn2.Hostname)
|
rtest.Equals(t, sn.Hostname, sn2.Hostname)
|
||||||
rtest.Equals(t, sn.Username, sn2.Username)
|
rtest.Equals(t, sn.Username, sn2.Username)
|
||||||
|
|
||||||
|
var cf restic.Config
|
||||||
|
|
||||||
|
// load and check Config
|
||||||
|
err = repo.LoadJSONUnpacked(context.TODO(), restic.ConfigFile, id, &cf)
|
||||||
|
rtest.OK(t, err)
|
||||||
|
|
||||||
|
rtest.Equals(t, cf.ChunkerPolynomial, repository.TestChunkerPol)
|
||||||
}
|
}
|
||||||
|
|
||||||
var repoFixture = filepath.Join("testdata", "test-repo.tar.gz")
|
var repoFixture = filepath.Join("testdata", "test-repo.tar.gz")
|
||||||
|
@ -36,7 +36,7 @@ func TestBackend(t testing.TB) (be restic.Backend, cleanup func()) {
|
|||||||
return mem.New(), func() {}
|
return mem.New(), func() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testChunkerPol = chunker.Pol(0x3DA3358B4DC173)
|
const TestChunkerPol = chunker.Pol(0x3DA3358B4DC173)
|
||||||
|
|
||||||
// TestRepositoryWithBackend returns a repository initialized with a test
|
// TestRepositoryWithBackend returns a repository initialized with a test
|
||||||
// password. If be is nil, an in-memory backend is used. A constant polynomial
|
// password. If be is nil, an in-memory backend is used. A constant polynomial
|
||||||
@ -53,7 +53,7 @@ func TestRepositoryWithBackend(t testing.TB, be restic.Backend) (r restic.Reposi
|
|||||||
|
|
||||||
repo := New(be)
|
repo := New(be)
|
||||||
|
|
||||||
cfg := restic.TestCreateConfig(t, testChunkerPol)
|
cfg := restic.TestCreateConfig(t, TestChunkerPol)
|
||||||
err := repo.init(context.TODO(), test.TestPassword, cfg)
|
err := repo.init(context.TODO(), test.TestPassword, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestRepository(): initialize repo failed: %v", err)
|
t.Fatalf("TestRepository(): initialize repo failed: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user