-
Notifications
You must be signed in to change notification settings - Fork 340
/
format_set_parameters.go
53 lines (40 loc) · 1.4 KB
/
format_set_parameters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
}