/
parameters.go
55 lines (41 loc) · 1.51 KB
/
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
54
55
package repo
import (
"context"
"os"
"path/filepath"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo/content"
)
// SetParameters changes mutable repository parameters.
func (r *directRepository) SetParameters(ctx context.Context, m content.MutableParameters, blobcfg content.BlobCfgBlob) error {
f := r.formatBlob
repoConfig, err := f.decryptFormatBytes(r.formatEncryptionKey)
if err != nil {
return errors.Wrap(err, "unable to decrypt repository config")
}
if err := m.Validate(); err != nil {
return errors.Wrap(err, "invalid parameters")
}
if err := blobcfg.Validate(); err != nil {
return errors.Wrap(err, "invalid blob-config options")
}
repoConfig.FormattingOptions.MutableParameters = m
if err := encryptFormatBytes(f, repoConfig, r.formatEncryptionKey, f.UniqueID); err != nil {
return errors.Errorf("unable to encrypt format bytes")
}
if err := writeBlobCfgBlob(ctx, r.blobs, f, blobcfg, r.formatEncryptionKey); err != nil {
return errors.Wrap(err, "unable to write blobcfg blob")
}
if err := writeFormatBlob(ctx, r.blobs, f, r.blobCfgBlob); err != nil {
return errors.Wrap(err, "unable to write format blob")
}
if cd := r.cachingOptions.CacheDirectory; cd != "" {
if err := os.Remove(filepath.Join(cd, FormatBlobID)); err != nil {
log(ctx).Errorf("unable to remove %s: %v", FormatBlobID, err)
}
if err := os.Remove(filepath.Join(cd, BlobCfgBlobID)); err != nil && !os.IsNotExist(err) {
log(ctx).Errorf("unable to remove %s: %v", BlobCfgBlobID, err)
}
}
return nil
}