mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-22 20:05:48 +02:00
merge of upstream/main + limitsize w/o DB
This commit is contained in:
@@ -18,13 +18,6 @@ import (
|
||||
"gitea.com/go-chi/binding"
|
||||
)
|
||||
|
||||
// UpdateGlobalRepoFrom for updating global repository setting
|
||||
type UpdateGlobalRepoFrom struct {
|
||||
RepoSizeLimit string
|
||||
LFSSizeLimit string
|
||||
LFSSizeInRepoSize bool
|
||||
}
|
||||
|
||||
// CreateRepoForm form for creating repository
|
||||
type CreateRepoForm struct {
|
||||
UID int64 `binding:"Required"`
|
||||
@@ -50,7 +43,11 @@ type CreateRepoForm struct {
|
||||
|
||||
ForkSingleBranch string
|
||||
ObjectFormatName string
|
||||
SizeLimit int64
|
||||
}
|
||||
|
||||
type UpdateGlobalRepoFrom struct {
|
||||
GitSizeMax string `form:"GitSizeMax"`
|
||||
LFSSizeMax string `form:"LFSSizeMax"`
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
@@ -114,8 +111,6 @@ type RepoSettingForm struct {
|
||||
PushMirrorInterval string
|
||||
Template bool
|
||||
EnablePrune bool
|
||||
RepoSizeLimit string
|
||||
LFSSizeLimit string
|
||||
|
||||
// Advanced settings
|
||||
EnableCode bool
|
||||
|
||||
+10
-52
@@ -186,13 +186,13 @@ func DownloadHandler(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- tracing helpers ----
|
||||
|
||||
// traceBatchDecision outputs a trace message for a batch decision
|
||||
func traceBatchDecision(rc *requestContext, op, msg string, args ...any) {
|
||||
prefix := fmt.Sprintf("LFS[BATCH][%s/%s][op=%s] ", rc.User, rc.Repo, op)
|
||||
log.Trace(prefix+msg, args...)
|
||||
}
|
||||
|
||||
// batchReqID returns a unique ID for a batch request
|
||||
func batchReqID(br *lfs_module.BatchRequest) string {
|
||||
h := sha1.New()
|
||||
h.Write([]byte(br.Operation))
|
||||
@@ -244,92 +244,50 @@ func BatchHandler(ctx *context.Context) {
|
||||
// Create content store once, reuse for tracing + normal logic below.
|
||||
contentStore := lfs_module.NewContentStore()
|
||||
|
||||
currCombinedTotal := repository.GitSize + repository.LFSSize
|
||||
|
||||
// Baseline repo stats and limits
|
||||
traceBatchDecision(rc, br.Operation,
|
||||
"req=%s auth=%t isUpload=%t repoID=%d sizes: git=%s lfs=%s combined=%s limits: repo=%s lfs=%s LFSSizeInRepoSize=%v",
|
||||
"req=%s auth=%t isUpload=%t repoID=%d sizes: git=%s lfs=%s limits: git=%s lfs=%s",
|
||||
reqID,
|
||||
ctx.IsSigned || ctx.Doer != nil,
|
||||
isUpload,
|
||||
repository.ID,
|
||||
base.FileSize(repository.GitSize),
|
||||
base.FileSize(repository.LFSSize),
|
||||
base.FileSize(currCombinedTotal),
|
||||
base.FileSize(repository.GetActualSizeLimit()),
|
||||
base.FileSize(repository.GetActualLFSSizeLimit()),
|
||||
setting.LFSSizeInRepoSize,
|
||||
setting.FormatRepositorySizeLimit(repository.GetActualSizeLimit()),
|
||||
setting.FormatRepositorySizeLimit(repository.GetActualLFSSizeLimit()),
|
||||
)
|
||||
|
||||
// Check LFS size limits for upload operations
|
||||
if isUpload && (repository.ShouldCheckLFSSize() || (setting.LFSSizeInRepoSize && repository.ShouldCheckRepoSize())) {
|
||||
if isUpload && repository.ShouldCheckLFSSize() {
|
||||
// Sum sizes of objects that are NEW TO THIS REPO (no meta row)
|
||||
var incomingNewToRepoLFS int64
|
||||
var invalidCount, metaMissingCount, metaPresentCount, storeExistsCount int64
|
||||
|
||||
for _, p := range br.Objects {
|
||||
if !p.IsValid() {
|
||||
invalidCount++
|
||||
continue
|
||||
}
|
||||
|
||||
meta, _ := git_model.GetLFSMetaObjectByOid(ctx, repository.ID, p.Oid)
|
||||
|
||||
exists, _ := contentStore.Exists(p)
|
||||
if exists {
|
||||
storeExistsCount++
|
||||
}
|
||||
|
||||
if meta == nil {
|
||||
metaMissingCount++
|
||||
incomingNewToRepoLFS += p.Size
|
||||
} else {
|
||||
metaPresentCount++
|
||||
}
|
||||
}
|
||||
|
||||
predictedLFS := repository.LFSSize + incomingNewToRepoLFS
|
||||
predictedTotal := repository.GitSize + predictedLFS
|
||||
|
||||
traceBatchDecision(rc, br.Operation,
|
||||
"req=%s accounting: objects=%d invalid=%d metaMissing=%d metaPresent=%d storeExists=%d incomingNewToRepoLFS=%s predictedLFS=%s predictedTotal=%s",
|
||||
reqID,
|
||||
len(br.Objects),
|
||||
invalidCount,
|
||||
metaMissingCount,
|
||||
metaPresentCount,
|
||||
storeExistsCount,
|
||||
base.FileSize(incomingNewToRepoLFS),
|
||||
base.FileSize(predictedLFS),
|
||||
base.FileSize(predictedTotal),
|
||||
)
|
||||
|
||||
// LFS-only limit if we are over, but size doesn't increase allow
|
||||
if repository.ShouldCheckLFSSize() && predictedLFS > repository.GetActualLFSSizeLimit() && predictedLFS > repository.LFSSize {
|
||||
if predictedLFS > repository.GetActualLFSSizeLimit() && predictedLFS > repository.LFSSize {
|
||||
traceBatchDecision(rc, br.Operation,
|
||||
"req=%s DECISION=FORBID reason=LFS_LIMIT predictedLFS=%s limit=%s",
|
||||
reqID, base.FileSize(predictedLFS), base.FileSize(repository.GetActualLFSSizeLimit()),
|
||||
"req=%s DECISION=FORBID reason=LFS_LIMIT predictedLFS=%s limit=%s (NewObjects=%d ObjectsPresentInStore=%d MetaPresent=%d StoreExists=%d Invalid=%d)",
|
||||
reqID, base.FileSize(predictedLFS), setting.FormatRepositorySizeLimit(repository.GetActualLFSSizeLimit()),
|
||||
)
|
||||
writeStatusMessage(ctx, http.StatusForbidden,
|
||||
fmt.Sprintf("LFS size %s would exceed limit %s",
|
||||
base.FileSize(predictedLFS), base.FileSize(repository.GetActualLFSSizeLimit())))
|
||||
base.FileSize(predictedLFS), setting.FormatRepositorySizeLimit(repository.GetActualLFSSizeLimit())))
|
||||
return
|
||||
}
|
||||
|
||||
// Combined limit (conservative: ignores git delta/removals) if we are over, but combined size doesn't increase allow
|
||||
if setting.LFSSizeInRepoSize && repository.ShouldCheckRepoSize() {
|
||||
if predictedTotal > repository.GetActualSizeLimit() && predictedTotal > currCombinedTotal {
|
||||
traceBatchDecision(rc, br.Operation,
|
||||
"req=%s DECISION=FORBID reason=COMBINED_LIMIT predictedTotal=%s limit=%s",
|
||||
reqID, base.FileSize(predictedTotal), base.FileSize(repository.GetActualSizeLimit()),
|
||||
)
|
||||
writeStatusMessage(ctx, http.StatusForbidden,
|
||||
fmt.Sprintf("Repository size %s after LFS addition would exceed limit %s",
|
||||
base.FileSize(predictedTotal), base.FileSize(repository.GetActualSizeLimit())))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
traceBatchDecision(rc, br.Operation, "req=%s DECISION=ALLOW size-check passed", reqID)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,6 @@ type CreateRepoOptions struct {
|
||||
TrustModel repo_model.TrustModelType
|
||||
MirrorInterval string
|
||||
ObjectFormatName string
|
||||
SizeLimit int64
|
||||
LFSSizeLimit int64
|
||||
}
|
||||
|
||||
func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir string, opts CreateRepoOptions) error {
|
||||
@@ -249,8 +247,6 @@ func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
|
||||
Status: opts.Status,
|
||||
IsEmpty: !opts.AutoInit,
|
||||
TrustModel: opts.TrustModel,
|
||||
SizeLimit: opts.SizeLimit,
|
||||
LFSSizeLimit: opts.LFSSizeLimit,
|
||||
IsMirror: opts.IsMirror,
|
||||
DefaultBranch: opts.DefaultBranch,
|
||||
DefaultWikiBranch: setting.Repository.DefaultBranch,
|
||||
|
||||
Reference in New Issue
Block a user