diff --git a/src/internal/kopia/conn.go b/src/internal/kopia/conn.go index 522472c01..5e0d3a14d 100644 --- a/src/internal/kopia/conn.go +++ b/src/internal/kopia/conn.go @@ -4,6 +4,7 @@ import ( "context" "path/filepath" "sync" + "time" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/repo/blob" @@ -21,6 +22,8 @@ const ( defaultKopiaConfigDir = "/tmp/" defaultKopiaConfigFile = "repository.config" defaultCompressor = "s2-default" + // Interval of 0 disables scheduling. + defaultSchedulingInterval = time.Second * 0 ) const defaultConfigErrTmpl = "setting default repo config values" @@ -237,6 +240,10 @@ func (w *conn) setDefaultConfigValues(ctx context.Context) error { changed = true } + if updateSchedulingOnPolicy(defaultSchedulingInterval, p) { + changed = true + } + if !changed { return nil } @@ -305,6 +312,19 @@ func updateRetentionOnPolicy(retention policy.RetentionPolicy, p *policy.Policy) return true } +func updateSchedulingOnPolicy( + interval time.Duration, + p *policy.Policy, +) bool { + if p.SchedulingPolicy.Interval() == interval { + return false + } + + p.SchedulingPolicy.SetInterval(interval) + + return true +} + func (w *conn) getGlobalPolicyOrEmpty(ctx context.Context) (*policy.Policy, error) { si := policy.GlobalPolicySourceInfo return w.getPolicyOrEmpty(ctx, si) diff --git a/src/internal/kopia/conn_test.go b/src/internal/kopia/conn_test.go index 66f52f017..137c58ac3 100644 --- a/src/internal/kopia/conn_test.go +++ b/src/internal/kopia/conn_test.go @@ -4,6 +4,7 @@ import ( "context" "math" "testing" + "time" "github.com/kopia/kopia/snapshot" "github.com/kopia/kopia/snapshot/policy" @@ -260,6 +261,18 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() { newRetention := policy.RetentionPolicy{KeepDaily: &newRetentionDaily} updateRetentionOnPolicy(newRetention, p) + return nil + }, + }, + { + name: "Scheduling", + checkFunc: func(t *testing.T, p *policy.Policy) { + t.Helper() + require.Equal(t, time.Second*0, p.SchedulingPolicy.Interval()) + }, + mutator: func(innerCtx context.Context, p *policy.Policy) error { + updateSchedulingOnPolicy(time.Second*42, p) + return nil }, },