Skip to content

Commit ac7ad10

Browse files
fuxiaoheiGiteaBot
authored andcommitted
Fix merging artifact chunks error when minio storage basepath is set (go-gitea#28555)
Related to go-gitea#28279 When merging artifact chunks, it lists chunks from storage. When storage is minio, chunk's path contains `MINIO_BASE_PATH` that makes merging break. <del>So trim the `MINIO_BASE_PATH` when handle chunks.</del> Update the chunk file's basename to retain necessary information. It ensures that the directory in the chunk's path remains unaffected.
1 parent 47f9b3f commit ac7ad10

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

routers/api/actions/artifacts_chunks.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ func saveUploadChunk(st storage.ObjectStorage, ctx *ArtifactContext,
2525
contentRange := ctx.Req.Header.Get("Content-Range")
2626
start, end, length := int64(0), int64(0), int64(0)
2727
if _, err := fmt.Sscanf(contentRange, "bytes %d-%d/%d", &start, &end, &length); err != nil {
28+
log.Warn("parse content range error: %v, content-range: %s", err, contentRange)
2829
return -1, fmt.Errorf("parse content range error: %v", err)
2930
}
3031
// build chunk store path
31-
storagePath := fmt.Sprintf("tmp%d/%d-%d-%d.chunk", runID, artifact.ID, start, end)
32+
storagePath := fmt.Sprintf("tmp%d/%d-%d-%d-%d.chunk", runID, runID, artifact.ID, start, end)
3233
// use io.TeeReader to avoid reading all body to md5 sum.
3334
// it writes data to hasher after reading end
3435
// if hash is not matched, delete the read-end result
@@ -57,6 +58,7 @@ func saveUploadChunk(st storage.ObjectStorage, ctx *ArtifactContext,
5758
}
5859

5960
type chunkFileItem struct {
61+
RunID int64
6062
ArtifactID int64
6163
Start int64
6264
End int64
@@ -66,9 +68,12 @@ type chunkFileItem struct {
6668
func listChunksByRunID(st storage.ObjectStorage, runID int64) (map[int64][]*chunkFileItem, error) {
6769
storageDir := fmt.Sprintf("tmp%d", runID)
6870
var chunks []*chunkFileItem
69-
if err := st.IterateObjects(storageDir, func(path string, obj storage.Object) error {
70-
item := chunkFileItem{Path: path}
71-
if _, err := fmt.Sscanf(path, filepath.Join(storageDir, "%d-%d-%d.chunk"), &item.ArtifactID, &item.Start, &item.End); err != nil {
71+
if err := st.IterateObjects(storageDir, func(fpath string, obj storage.Object) error {
72+
baseName := filepath.Base(fpath)
73+
// when read chunks from storage, it only contains storage dir and basename,
74+
// no matter the subdirectory setting in storage config
75+
item := chunkFileItem{Path: storageDir + "/" + baseName}
76+
if _, err := fmt.Sscanf(baseName, "%d-%d-%d-%d.chunk", &item.RunID, &item.ArtifactID, &item.Start, &item.End); err != nil {
7277
return fmt.Errorf("parse content range error: %v", err)
7378
}
7479
chunks = append(chunks, &item)

0 commit comments

Comments
 (0)