summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorFuXiaoHei <fuxiaohei@vip.qq.com>2024-01-22 09:49:21 +0800
committerGitHub <noreply@github.com>2024-01-22 09:49:21 +0800
commit7f0ce2dfc7f4a0c50f6895f6d478f5230089f1c7 (patch)
tree97a3967f7bf8bcd02bf23f51e2bbc817ed2eedd5 /routers/api
parentb7c944b9e4e9f847719fbce421b2f4fee7281187 (diff)
downloadgitea-7f0ce2dfc7f4a0c50f6895f6d478f5230089f1c7.tar.gz
gitea-7f0ce2dfc7f4a0c50f6895f6d478f5230089f1c7.zip
Fix uploaded artifacts should be overwritten (#28726) backport v1.21 (#28832)
Backport https://github.com/go-gitea/gitea/pull/28726 by @fuxiaohei Fix Uploaded artifacts should be overwritten https://github.com/go-gitea/gitea/issues/28549 When upload different content to uploaded artifact, it checks that content size is not match in db record with previous artifact size, then the new artifact is refused. Now if it finds uploading content size is not matching db record when receiving chunks, it updates db records to follow the latest size value.
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/actions/artifacts.go9
-rw-r--r--routers/api/actions/artifacts_chunks.go9
2 files changed, 15 insertions, 3 deletions
diff --git a/routers/api/actions/artifacts.go b/routers/api/actions/artifacts.go
index c45dc667af..9da48cc5a6 100644
--- a/routers/api/actions/artifacts.go
+++ b/routers/api/actions/artifacts.go
@@ -257,8 +257,11 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
return
}
- // update artifact size if zero
- if artifact.FileSize == 0 || artifact.FileCompressedSize == 0 {
+ // update artifact size if zero or not match, over write artifact size
+ if artifact.FileSize == 0 ||
+ artifact.FileCompressedSize == 0 ||
+ artifact.FileSize != fileRealTotalSize ||
+ artifact.FileCompressedSize != chunksTotalSize {
artifact.FileSize = fileRealTotalSize
artifact.FileCompressedSize = chunksTotalSize
artifact.ContentEncoding = ctx.Req.Header.Get("Content-Encoding")
@@ -267,6 +270,8 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
ctx.Error(http.StatusInternalServerError, "Error update artifact")
return
}
+ log.Debug("[artifact] update artifact size, artifact_id: %d, size: %d, compressed size: %d",
+ artifact.ID, artifact.FileSize, artifact.FileCompressedSize)
}
ctx.JSON(http.StatusOK, map[string]string{
diff --git a/routers/api/actions/artifacts_chunks.go b/routers/api/actions/artifacts_chunks.go
index 0e0cf8a3aa..69801df787 100644
--- a/routers/api/actions/artifacts_chunks.go
+++ b/routers/api/actions/artifacts_chunks.go
@@ -182,7 +182,14 @@ func mergeChunksForArtifact(ctx *ArtifactContext, chunks []*chunkFileItem, st st
}()
// save storage path to artifact
- log.Debug("[artifact] merge chunks to artifact: %d, %s", artifact.ID, storagePath)
+ log.Debug("[artifact] merge chunks to artifact: %d, %s, old:%s", artifact.ID, storagePath, artifact.StoragePath)
+ // if artifact is already uploaded, delete the old file
+ if artifact.StoragePath != "" {
+ if err := st.Delete(artifact.StoragePath); err != nil {
+ log.Warn("Error deleting old artifact: %s, %v", artifact.StoragePath, err)
+ }
+ }
+
artifact.StoragePath = storagePath
artifact.Status = int64(actions.ArtifactStatusUploadConfirmed)
if err := actions.UpdateArtifactByID(ctx, artifact.ID, artifact); err != nil {