MCPcopy
hub / github.com/kopia/kopia / migrateSinglePolicy

Method migrateSinglePolicy

cli/command_snapshot_migrate.go:186–210  ·  view source on GitHub ↗
(ctx context.Context, sourceRepo repo.Repository, destRepo repo.RepositoryWriter, si snapshot.SourceInfo)

Source from the content-addressed store, hash-verified

184}
185
186func (c *commandSnapshotMigrate) migrateSinglePolicy(ctx context.Context, sourceRepo repo.Repository, destRepo repo.RepositoryWriter, si snapshot.SourceInfo) error {
187 pol, err := policy.GetDefinedPolicy(ctx, sourceRepo, si)
188 if errors.Is(err, policy.ErrPolicyNotFound) {
189 return nil
190 }
191
192 if err != nil {
193 return errors.Wrapf(err, "unable to migrate policy for %v", si)
194 }
195
196 _, err = policy.GetDefinedPolicy(ctx, destRepo, si)
197 if err == nil {
198 if !c.migrateOverwritePolicies {
199 log(ctx).Infof("policy already set for %v", si)
200 // already have destination policy
201 return nil
202 }
203 } else if !errors.Is(err, policy.ErrPolicyNotFound) {
204 return errors.Wrapf(err, "unable to migrate policy for %v", si)
205 }
206
207 log(ctx).Infof("migrating policy for %v", si)
208
209 return errors.Wrap(policy.SetPolicy(ctx, destRepo, si, pol), "error setting policy")
210}
211
212func (c *commandSnapshotMigrate) findPreviousSnapshotManifestWithStartTime(ctx context.Context, rep repo.Repository, sourceInfo snapshot.SourceInfo, startTime fs.UTCTimestamp) (*snapshot.Manifest, error) {
213 previous, err := snapshot.ListSnapshots(ctx, rep, sourceInfo)

Callers 2

migrateAllPoliciesMethod · 0.95

Calls 2

GetDefinedPolicyFunction · 0.92
SetPolicyFunction · 0.92

Tested by

no test coverage detected