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.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 loadMirrorFrom(rootCfg ConfigProvider) {
  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. // DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version
  26. // if these are removed, the warning will not be shown
  27. deprecatedSetting(rootCfg, "repository", "DISABLE_MIRRORS", "mirror", "ENABLED", "v1.19.0")
  28. if ConfigSectionKeyBool(rootCfg.Section("repository"), "DISABLE_MIRRORS") {
  29. Mirror.DisableNewPull = true
  30. }
  31. if err := rootCfg.Section("mirror").MapTo(&Mirror); err != nil {
  32. log.Fatal("Failed to map Mirror settings: %v", err)
  33. }
  34. if !Mirror.Enabled {
  35. Mirror.DisableNewPull = true
  36. Mirror.DisableNewPush = true
  37. }
  38. if Mirror.MinInterval.Minutes() < 1 {
  39. log.Warn("Mirror.MinInterval is too low, set to 1 minute")
  40. Mirror.MinInterval = 1 * time.Minute
  41. }
  42. if Mirror.DefaultInterval < Mirror.MinInterval {
  43. if time.Hour*8 < Mirror.MinInterval {
  44. Mirror.DefaultInterval = Mirror.MinInterval
  45. } else {
  46. Mirror.DefaultInterval = time.Hour * 8
  47. }
  48. log.Warn("Mirror.DefaultInterval is less than Mirror.MinInterval, set to %s", Mirror.DefaultInterval.String())
  49. }
  50. }