summaryrefslogtreecommitdiffstats
path: root/routers/api/packages/maven/maven.go
diff options
context:
space:
mode:
authorGusted <gusted@noreply.codeberg.org>2025-01-09 18:39:38 +0100
committerGusted <gusted@noreply.codeberg.org>2025-01-09 18:39:38 +0100
commit46e15e57f782c968f533bd6a74b7da82c6ddcbaf (patch)
tree186130983490799b4098f4c8a26dc62180690e9d /routers/api/packages/maven/maven.go
parenti18n: update of translations from Codeberg Translate (#6451) (diff)
downloadforgejo-46e15e57f782c968f533bd6a74b7da82c6ddcbaf.tar.xz
forgejo-46e15e57f782c968f533bd6a74b7da82c6ddcbaf.zip
port(gitea#31954): Add lock for parallel maven upload (#6513)
Backport #31851 Fix #30171 --- Fixes https://github.com/go-gitea/gitea/issues/30171, this is also a issue in Forgejo. Backport the implementation that uses the existing sync module which does not work for multiple instances which is perfectly fine for Forgejo for now. (cherry picked from commit 9c990ac043a0167dc59f1c822988ed2316f7c1df) Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6513 Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Diffstat (limited to 'routers/api/packages/maven/maven.go')
-rw-r--r--routers/api/packages/maven/maven.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/routers/api/packages/maven/maven.go b/routers/api/packages/maven/maven.go
index 521ef2209a..92f20255e1 100644
--- a/routers/api/packages/maven/maven.go
+++ b/routers/api/packages/maven/maven.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/modules/log"
packages_module "code.gitea.io/gitea/modules/packages"
maven_module "code.gitea.io/gitea/modules/packages/maven"
+ "code.gitea.io/gitea/modules/sync"
"code.gitea.io/gitea/routers/api/packages/helper"
"code.gitea.io/gitea/services/context"
packages_service "code.gitea.io/gitea/services/packages"
@@ -228,6 +229,8 @@ func servePackageFile(ctx *context.Context, params parameters, serveContent bool
helper.ServePackageFile(ctx, s, u, pf, opts)
}
+var mavenUploadLock = sync.NewExclusivePool()
+
// UploadPackageFile adds a file to the package. If the package does not exist, it gets created.
func UploadPackageFile(ctx *context.Context) {
params, err := extractPathParameters(ctx)
@@ -246,6 +249,9 @@ func UploadPackageFile(ctx *context.Context) {
packageName := params.GroupID + "-" + params.ArtifactID
+ mavenUploadLock.CheckIn(packageName)
+ defer mavenUploadLock.CheckOut(packageName)
+
buf, err := packages_module.CreateHashedBufferFromReader(ctx.Req.Body)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)