mirror of
https://github.com/kopia/kopia.git
synced 2026-03-28 11:03:44 -04:00
* Fix caching issue of storage blob config blob * Add tests to ensure retention is set during config Ensure retention is properly set when either changing retention options or initializing the repo with retention.
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package format
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/internal/feature"
|
|
"github.com/kopia/kopia/repo/blob"
|
|
)
|
|
|
|
// SetParameters sets the mutable repository parameters.
|
|
func (m *Manager) SetParameters(
|
|
ctx context.Context,
|
|
mp MutableParameters,
|
|
blobcfg BlobStorageConfiguration,
|
|
requiredFeatures []feature.Required,
|
|
) error {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
|
|
if err := mp.Validate(); err != nil {
|
|
return errors.Wrap(err, "invalid parameters")
|
|
}
|
|
|
|
if err := blobcfg.Validate(); err != nil {
|
|
return errors.Wrap(err, "invalid blob-config options")
|
|
}
|
|
|
|
m.repoConfig.ContentFormat.MutableParameters = mp
|
|
m.repoConfig.RequiredFeatures = requiredFeatures
|
|
|
|
if err := m.j.EncryptRepositoryConfig(m.repoConfig, m.formatEncryptionKey); err != nil {
|
|
return errors.Errorf("unable to encrypt format bytes")
|
|
}
|
|
|
|
if err := m.j.WriteBlobCfgBlob(ctx, m.blobs, blobcfg, m.formatEncryptionKey); err != nil {
|
|
return errors.Wrap(err, "unable to write blobcfg blob")
|
|
}
|
|
|
|
// At this point the new blobcfg is persisted in the blob layer. Setting this
|
|
// here also ensures the call below properly sets retention on the kopia
|
|
// repository blob.
|
|
m.blobCfgBlob = blobcfg
|
|
|
|
if err := m.j.WriteKopiaRepositoryBlob(ctx, m.blobs, m.blobCfgBlob); err != nil {
|
|
return errors.Wrap(err, "unable to write format blob")
|
|
}
|
|
|
|
m.cache.Remove(ctx, []blob.ID{KopiaRepositoryBlobID, KopiaBlobCfgBlobID})
|
|
|
|
return nil
|
|
}
|