SizeLimit w/o DB changes

This commit is contained in:
DmitryFrolovTri
2026-01-13 09:18:03 +00:00
parent 7b10eb20a5
commit 7942523c3f
22 changed files with 303 additions and 880 deletions
+7 -32
View File
@@ -6,7 +6,6 @@ package setting
import (
"os/exec"
"path/filepath"
"strconv"
"strings"
"code.gitea.io/gitea/modules/log"
@@ -56,6 +55,8 @@ var (
DisableDownloadSourceArchives bool
AllowForkWithoutMaximumLimit bool
AllowForkIntoSameOwner bool
GitSizeMax int64 `ini:"GIT_SIZE_MAX"`
LFSSizeMax int64 `ini:"LFS_SIZE_MAX"`
// StreamArchives makes Gitea stream git archive files to the client directly instead of creating an archive first.
// Ideally all users should use this streaming method. However, at the moment we don't know whether there are
@@ -276,36 +277,11 @@ var (
}
RepoRootPath string
ScriptType = "bash"
// Repository size limits
RepoSizeLimit int64 = -1
LFSSizeLimit int64 = -1
LFSSizeInRepoSize bool
)
func SaveGlobalRepositorySetting(repoSizeLimit, lfsSizeLimit int64, lfsSizeInRepoSize bool) error {
RepoSizeLimit = repoSizeLimit
LFSSizeLimit = lfsSizeLimit
LFSSizeInRepoSize = lfsSizeInRepoSize
cfg, err := CfgProvider.PrepareSaving()
if err != nil {
return err
}
sec := cfg.Section("repository")
if RepoSizeLimit == -1 {
sec.Key("REPO_SIZE_LIMIT").SetValue("-1")
} else {
sec.Key("REPO_SIZE_LIMIT").SetValue(humanize.Bytes(uint64(RepoSizeLimit)))
}
if LFSSizeLimit == -1 {
sec.Key("LFS_SIZE_LIMIT").SetValue("-1")
} else {
sec.Key("LFS_SIZE_LIMIT").SetValue(humanize.Bytes(uint64(LFSSizeLimit)))
}
sec.Key("LFS_SIZE_IN_REPO_SIZE").SetValue(strconv.FormatBool(LFSSizeInRepoSize))
return cfg.Save()
func UpdateGlobalRepositoryLimit(gitSizeMax, lfsSizeMax int64) {
Repository.GitSizeMax = gitSizeMax
Repository.LFSSizeMax = lfsSizeMax
}
func parseSize(sec ConfigSection, key string, def int64) int64 {
@@ -328,9 +304,8 @@ func loadRepositoryFrom(rootCfg ConfigProvider) {
// Determine and create root git repository path.
sec := rootCfg.Section("repository")
RepoSizeLimit = parseSize(sec, "REPO_SIZE_LIMIT", -1)
LFSSizeLimit = parseSize(sec, "LFS_SIZE_LIMIT", -1)
LFSSizeInRepoSize = sec.Key("LFS_SIZE_IN_REPO_SIZE").MustBool(false)
Repository.GitSizeMax = parseSize(sec, "GIT_SIZE_MAX", -1)
Repository.LFSSizeMax = parseSize(sec, "LFS_SIZE_MAX", -1)
Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()