mirror of
https://github.com/go-gitea/gitea.git
synced 2026-06-12 18:03:53 +02:00
Config parameter REPO_SIZE_LIMIT = XXXX (should accept bytes human readable) part1, sensible defaults, app.ini saving
This commit is contained in:
parent
414c90263a
commit
31600a0159
@ -7,10 +7,10 @@ import (
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
// enumerates all the policy repository creating
|
||||
@ -271,7 +271,7 @@ var (
|
||||
RepoSizeLimit int64 = 0
|
||||
)
|
||||
|
||||
func SaveGlobalRepositorySetting(enable_size_limit bool, repo_size_limit int64) {
|
||||
func SaveGlobalRepositorySetting(enable_size_limit bool, repo_size_limit int64) error {
|
||||
EnableSizeLimit = enable_size_limit
|
||||
RepoSizeLimit = repo_size_limit
|
||||
sec := CfgProvider.Section("repository")
|
||||
@ -281,7 +281,12 @@ func SaveGlobalRepositorySetting(enable_size_limit bool, repo_size_limit int64)
|
||||
sec.Key("ENABLE_SIZE_LIMIT").SetValue("false")
|
||||
}
|
||||
|
||||
sec.Key("REPO_SIZE_LIMIT").SetValue(strconv.FormatInt(RepoSizeLimit, 10))
|
||||
sec.Key("REPO_SIZE_LIMIT").SetValue(humanize.Bytes(uint64(RepoSizeLimit)))
|
||||
if err := CfgProvider.Save(); err != nil {
|
||||
log.Fatal("Failed to save config file: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadRepositoryFrom(rootCfg ConfigProvider) {
|
||||
@ -289,8 +294,16 @@ func loadRepositoryFrom(rootCfg ConfigProvider) {
|
||||
|
||||
// Determine and create root git repository path.
|
||||
sec := rootCfg.Section("repository")
|
||||
EnableSizeLimit = sec.Key("ENABLE_SIZE_LIMIT").MustBool(true)
|
||||
RepoSizeLimit = sec.Key("REPO_SIZE_LIMIT").MustInt64(1024 * 1024 * 10)
|
||||
EnableSizeLimit = sec.Key("ENABLE_SIZE_LIMIT").MustBool(false)
|
||||
|
||||
v, err := humanize.ParseBytes(sec.Key("REPO_SIZE_LIMIT").MustString("0"))
|
||||
|
||||
if err == nil {
|
||||
RepoSizeLimit = int64(v)
|
||||
} else {
|
||||
RepoSizeLimit = 0
|
||||
}
|
||||
|
||||
Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
|
||||
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
|
||||
Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
|
||||
|
||||
@ -3013,6 +3013,7 @@ config.repository_config = Repository Configuration
|
||||
config.enable_size_limit = Enable Size Limit
|
||||
config.repo_size_limit = Default Repository Size Limit
|
||||
config.invalid_repo_size = Invalid repository size.
|
||||
config.save_repo_size_setting_failed = Failed to save global repository settings
|
||||
config.repository_setting_success = Global repository setting has been updated.
|
||||
|
||||
config.git_config = Git Configuration
|
||||
|
||||
@ -55,7 +55,7 @@ func UpdateRepoPost(ctx *context.Context) {
|
||||
ctx.Data["RepoSizeLimit"] = form.RepoSizeLimit
|
||||
|
||||
if err != nil {
|
||||
ctx.Data["Err_Repo_Size_Limit"] = true
|
||||
ctx.Data["Err_Repo_Size_Limit"] = err.Error()
|
||||
explore.RenderRepoSearch(ctx, &explore.RepoSearchOptions{
|
||||
Private: true,
|
||||
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||
@ -65,7 +65,18 @@ func UpdateRepoPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
setting.SaveGlobalRepositorySetting(form.EnableSizeLimit, repo_size_limit)
|
||||
err = setting.SaveGlobalRepositorySetting(form.EnableSizeLimit, repo_size_limit)
|
||||
|
||||
if err != nil {
|
||||
ctx.Data["Err_Repo_Size_Save"] = err.Error()
|
||||
explore.RenderRepoSearch(ctx, &explore.RepoSearchOptions{
|
||||
Private: true,
|
||||
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||
TplName: tplRepos,
|
||||
OnlyShowRelevant: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("admin.config.repository_setting_success"))
|
||||
ctx.Redirect(setting.AppSubURL + "/admin/repos")
|
||||
|
||||
@ -142,7 +142,14 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
if ctx.Data["Err_Repo_Size_Limit"] != nil {
|
||||
ctx.RenderWithErr(ctx.Tr("admin.config.invalid_repo_size"), opts.TplName, nil)
|
||||
ctx.RenderWithErr(ctx.Tr("admin.config.invalid_repo_size")+" "+ctx.Data["Err_Repo_Size_Limit"].(string),
|
||||
opts.TplName, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Data["Err_Repo_Size_Save"] != nil {
|
||||
ctx.RenderWithErr(ctx.Tr("admin.config.save_repo_size_setting_failed")+" "+ctx.Data["Err_Repo_Size_Save"].(string),
|
||||
opts.TplName, nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user