From 54f0293f0ab73f357f545f8e05d16f9b254aba5e Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 8 Apr 2017 17:27:26 +0200 Subject: Mirror sync interval specified as duration string (#1407) * Sync interval specifed as duration string * Changed mirror interval text * make fmt * Add MinInterval for mirror sync * Use duration internally * Changed min default to 10m * make fmt * Incorrect default * Removed defaults in MustDuration() * Add Mirror interval migration * Default values corrected * Use transaction during migration * Change http 500 to page with error message * Cleanup session.commit() --- routers/repo/setting.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'routers/repo/setting.go') diff --git a/routers/repo/setting.go b/routers/repo/setting.go index fb6d68ad9b..ed7254fe1b 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -111,12 +111,15 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { return } - if form.Interval > 0 { + interval, err := time.ParseDuration(form.Interval) + if err != nil || 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 = form.Interval - ctx.Repo.Mirror.NextUpdate = time.Now().Add(time.Duration(form.Interval) * time.Hour) + ctx.Repo.Mirror.Interval = interval + ctx.Repo.Mirror.NextUpdate = time.Now().Add(interval) if err := models.UpdateMirror(ctx.Repo.Mirror); err != nil { - ctx.Handle(500, "UpdateMirror", err) + ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) return } } -- cgit v1.2.3