From 599adde1bc3670279d371fd9f2620c2829286bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Br=C3=B6ms?= <9416498+cez81@users.noreply.github.com> Date: Fri, 9 Nov 2018 00:58:02 +0100 Subject: [PATCH] Add option to disable automatic mirror syncing. (#5242) Setting the interval to 0 will disable to automatic syncing. --- models/repo_mirror.go | 7 ++++++- options/locale/locale_en-US.ini | 2 +- routers/repo/setting.go | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/models/repo_mirror.go b/models/repo_mirror.go index 447d055307..9f8c9bee65 100644 --- a/models/repo_mirror.go +++ b/models/repo_mirror.go @@ -63,7 +63,11 @@ func (m *Mirror) AfterLoad(session *xorm.Session) { // ScheduleNextUpdate calculates and sets next update time. func (m *Mirror) ScheduleNextUpdate() { - m.NextUpdateUnix = util.TimeStampNow().AddDuration(m.Interval) + if m.Interval != 0 { + m.NextUpdateUnix = util.TimeStampNow().AddDuration(m.Interval) + } else { + m.NextUpdateUnix = 0 + } } func remoteAddress(repoPath string) (string, error) { @@ -302,6 +306,7 @@ func MirrorUpdate() { if err := x. Where("next_update_unix<=?", time.Now().Unix()). + And("next_update_unix!=0"). Iterate(new(Mirror), func(idx int, bean interface{}) error { m := bean.(*Mirror) if m.Repo == nil { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6f32341575..a82acc3dd1 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -524,7 +524,7 @@ create_repo = Create Repository default_branch = Default Branch mirror_prune = Prune mirror_prune_desc = Remove obsolete remote-tracking references -mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's') +mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync. mirror_interval_invalid = The mirror interval is not valid. mirror_address = Clone From URL mirror_address_desc = Include any required authorization credentials in the URL. diff --git a/routers/repo/setting.go b/routers/repo/setting.go index ff6b07f8e0..61b00d793b 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -117,12 +117,16 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { } interval, err := time.ParseDuration(form.Interval) - if err != nil || interval < setting.Mirror.MinInterval { + if err != nil && (interval != 0 || interval < setting.Mirror.MinInterval) { ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) } else { ctx.Repo.Mirror.EnablePrune = form.EnablePrune ctx.Repo.Mirror.Interval = interval - ctx.Repo.Mirror.NextUpdateUnix = util.TimeStampNow().AddDuration(interval) + if interval != 0 { + ctx.Repo.Mirror.NextUpdateUnix = util.TimeStampNow().AddDuration(interval) + } else { + ctx.Repo.Mirror.NextUpdateUnix = 0 + } if err := models.UpdateMirror(ctx.Repo.Mirror); err != nil { ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) return