MCPcopy
hub / github.com/kopia/kopia / run

Method run

cli/command_policy_set.go:61–94  ·  view source on GitHub ↗
(ctx context.Context, rep repo.RepositoryWriter)

Source from the content-addressed store, hash-verified

59)
60
61func (c *commandPolicySet) run(ctx context.Context, rep repo.RepositoryWriter) error {
62 targets, err := c.policyTargets(ctx, rep)
63 if err != nil {
64 return err
65 }
66
67 for _, target := range targets {
68 p, err := policy.GetDefinedPolicy(ctx, rep, target)
69
70 switch {
71 case errors.Is(err, policy.ErrPolicyNotFound):
72 p = &policy.Policy{}
73 case err != nil:
74 return errors.Wrap(err, "could not get defined policy")
75 }
76
77 log(ctx).Infof("Setting policy for %v", target)
78
79 changeCount := 0
80 if err := c.setPolicyFromFlags(ctx, p, &changeCount); err != nil {
81 return err
82 }
83
84 if changeCount == 0 {
85 return errors.New("no changes specified")
86 }
87
88 if err := policy.SetPolicy(ctx, rep, target, p); err != nil {
89 return errors.Wrapf(err, "can't save policy for %v", target)
90 }
91 }
92
93 return nil
94}
95
96func (c *commandPolicySet) setPolicyFromFlags(ctx context.Context, p *policy.Policy, changeCount *int) error {
97 if err := c.setRetentionPolicyFromFlags(ctx, &p.RetentionPolicy, changeCount); err != nil {

Callers

nothing calls this directly

Calls 4

setPolicyFromFlagsMethod · 0.95
GetDefinedPolicyFunction · 0.92
SetPolicyFunction · 0.92
policyTargetsMethod · 0.80

Tested by

no test coverage detected