2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

repository: unify repository version-specific initialization

Mark the master index as compressed also when initializing a new
repository. This is only relevant for testing.
This commit is contained in:
Michael Eischer 2022-04-29 23:12:43 +02:00
parent 8776031f96
commit abe5935693

View File

@ -116,6 +116,14 @@ func (r *Repository) DisableAutoIndexUpdate() {
r.noAutoIndexUpdate = true r.noAutoIndexUpdate = true
} }
// setConfig assigns the given config and updates the repository parameters accordingly
func (r *Repository) setConfig(cfg restic.Config) {
r.cfg = cfg
if r.cfg.Version >= 2 {
r.idx.markCompressed()
}
}
// Config returns the repository configuration. // Config returns the repository configuration.
func (r *Repository) Config() restic.Config { func (r *Repository) Config() restic.Config {
return r.cfg return r.cfg
@ -772,15 +780,14 @@ func (r *Repository) SearchKey(ctx context.Context, password string, maxKeys int
r.dataPM.key = key.master r.dataPM.key = key.master
r.treePM.key = key.master r.treePM.key = key.master
r.keyName = key.Name() r.keyName = key.Name()
r.cfg, err = restic.LoadConfig(ctx, r) cfg, err := restic.LoadConfig(ctx, r)
if err == crypto.ErrUnauthenticated { if err == crypto.ErrUnauthenticated {
return errors.Fatalf("config or key %v is damaged: %v", key.Name(), err) return errors.Fatalf("config or key %v is damaged: %v", key.Name(), err)
} else if err != nil { } else if err != nil {
return errors.Fatalf("config cannot be loaded: %v", err) return errors.Fatalf("config cannot be loaded: %v", err)
} }
if r.Config().Version >= 2 {
r.idx.markCompressed() r.setConfig(cfg)
}
return nil return nil
} }
@ -826,7 +833,7 @@ func (r *Repository) init(ctx context.Context, password string, cfg restic.Confi
r.dataPM.key = key.master r.dataPM.key = key.master
r.treePM.key = key.master r.treePM.key = key.master
r.keyName = key.Name() r.keyName = key.Name()
r.cfg = cfg r.setConfig(cfg)
_, err = r.SaveJSONUnpacked(ctx, restic.ConfigFile, cfg) _, err = r.SaveJSONUnpacked(ctx, restic.ConfigFile, cfg)
return err return err
} }