mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 04:05:42 +01:00
fix(f3): do not run the F3 CLI if F3 is disabled
This commit is contained in:
parent
53d4e90411
commit
50afca7961
3 changed files with 14 additions and 0 deletions
|
@ -6,10 +6,12 @@ package forgejo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/storage"
|
"code.gitea.io/gitea/modules/storage"
|
||||||
"code.gitea.io/gitea/services/f3/util"
|
"code.gitea.io/gitea/services/f3/util"
|
||||||
|
|
||||||
|
@ -41,6 +43,11 @@ func SubcmdF3Mirror(ctx context.Context) *cli.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runMirror(ctx context.Context, c *cli.Context, action cli.ActionFunc) error {
|
func runMirror(ctx context.Context, c *cli.Context, action cli.ActionFunc) error {
|
||||||
|
setting.LoadF3Setting()
|
||||||
|
if !setting.F3.Enabled {
|
||||||
|
return errors.New("F3 is disabled, it is not ready to be used and is only present for development purposes")
|
||||||
|
}
|
||||||
|
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
if !ContextGetNoInit(ctx) {
|
if !ContextGetNoInit(ctx) {
|
||||||
ctx, cancel = installSignals(ctx)
|
ctx, cancel = installSignals(ctx)
|
||||||
|
|
|
@ -15,6 +15,10 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func LoadF3Setting() {
|
||||||
|
loadF3From(CfgProvider)
|
||||||
|
}
|
||||||
|
|
||||||
func loadF3From(rootCfg ConfigProvider) {
|
func loadF3From(rootCfg ConfigProvider) {
|
||||||
if err := rootCfg.Section("F3").MapTo(&F3); err != nil {
|
if err := rootCfg.Section("F3").MapTo(&F3); err != nil {
|
||||||
log.Fatal("Failed to map F3 settings: %v", err)
|
log.Fatal("Failed to map F3 settings: %v", err)
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/cmd/forgejo"
|
"code.gitea.io/gitea/cmd/forgejo"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
"code.gitea.io/gitea/services/f3/driver/options"
|
"code.gitea.io/gitea/services/f3/driver/options"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
|
@ -56,6 +58,7 @@ func runApp(ctx context.Context, args ...string) (string, error) {
|
||||||
|
|
||||||
func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
|
func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
defer test.MockVariableValue(&setting.F3.Enabled, true)()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue