github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/setting/mirror.go (about)

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