You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mirror.go 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. import (
  5. "time"
  6. "code.gitea.io/gitea/modules/log"
  7. )
  8. // Mirror settings
  9. var Mirror = struct {
  10. Enabled bool
  11. DisableNewPull bool
  12. DisableNewPush bool
  13. DefaultInterval time.Duration
  14. MinInterval time.Duration
  15. }{
  16. Enabled: true,
  17. DisableNewPull: false,
  18. DisableNewPush: false,
  19. MinInterval: 10 * time.Minute,
  20. DefaultInterval: 8 * time.Hour,
  21. }
  22. func newMirror() {
  23. // Handle old configuration through `[repository]` `DISABLE_MIRRORS`
  24. // - please note this was badly named and only disabled the creation of new pull mirrors
  25. // FIXME: DEPRECATED to be removed in v1.18.0
  26. deprecatedSetting("repository", "DISABLE_MIRRORS", "mirror", "ENABLED")
  27. if Cfg.Section("repository").Key("DISABLE_MIRRORS").MustBool(false) {
  28. Mirror.DisableNewPull = true
  29. }
  30. if err := Cfg.Section("mirror").MapTo(&Mirror); err != nil {
  31. log.Fatal("Failed to map Mirror settings: %v", err)
  32. }
  33. if !Mirror.Enabled {
  34. Mirror.DisableNewPull = true
  35. Mirror.DisableNewPush = true
  36. }
  37. if Mirror.MinInterval.Minutes() < 1 {
  38. log.Warn("Mirror.MinInterval is too low, set to 1 minute")
  39. Mirror.MinInterval = 1 * time.Minute
  40. }
  41. if Mirror.DefaultInterval < Mirror.MinInterval {
  42. if time.Hour*8 < Mirror.MinInterval {
  43. Mirror.DefaultInterval = Mirror.MinInterval
  44. } else {
  45. Mirror.DefaultInterval = time.Hour * 8
  46. }
  47. log.Warn("Mirror.DefaultInterval is less than Mirror.MinInterval, set to %s", Mirror.DefaultInterval.String())
  48. }
  49. }