loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix merging artifact chunks error when minio storage basepath is set (#28555)

Related to https://github.com/go-gitea/gitea/issues/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.

authored by

FuXiaoHei and committed by
GitHub
fe5a6163 caceb433

+9 -4
+9 -4
routers/api/actions/artifacts_chunks.go
··· 26 26 contentRange := ctx.Req.Header.Get("Content-Range") 27 27 start, end, length := int64(0), int64(0), int64(0) 28 28 if _, err := fmt.Sscanf(contentRange, "bytes %d-%d/%d", &start, &end, &length); err != nil { 29 + log.Warn("parse content range error: %v, content-range: %s", err, contentRange) 29 30 return -1, fmt.Errorf("parse content range error: %v", err) 30 31 } 31 32 // build chunk store path 32 - storagePath := fmt.Sprintf("tmp%d/%d-%d-%d.chunk", runID, artifact.ID, start, end) 33 + storagePath := fmt.Sprintf("tmp%d/%d-%d-%d-%d.chunk", runID, runID, artifact.ID, start, end) 33 34 // use io.TeeReader to avoid reading all body to md5 sum. 34 35 // it writes data to hasher after reading end 35 36 // if hash is not matched, delete the read-end result ··· 58 59 } 59 60 60 61 type chunkFileItem struct { 62 + RunID int64 61 63 ArtifactID int64 62 64 Start int64 63 65 End int64 ··· 67 69 func listChunksByRunID(st storage.ObjectStorage, runID int64) (map[int64][]*chunkFileItem, error) { 68 70 storageDir := fmt.Sprintf("tmp%d", runID) 69 71 var chunks []*chunkFileItem 70 - if err := st.IterateObjects(storageDir, func(path string, obj storage.Object) error { 71 - item := chunkFileItem{Path: path} 72 - if _, err := fmt.Sscanf(path, filepath.Join(storageDir, "%d-%d-%d.chunk"), &item.ArtifactID, &item.Start, &item.End); err != nil { 72 + if err := st.IterateObjects(storageDir, func(fpath string, obj storage.Object) error { 73 + baseName := filepath.Base(fpath) 74 + // when read chunks from storage, it only contains storage dir and basename, 75 + // no matter the subdirectory setting in storage config 76 + item := chunkFileItem{Path: storageDir + "/" + baseName} 77 + if _, err := fmt.Sscanf(baseName, "%d-%d-%d-%d.chunk", &item.RunID, &item.ArtifactID, &item.Start, &item.End); err != nil { 73 78 return fmt.Errorf("parse content range error: %v", err) 74 79 } 75 80 chunks = append(chunks, &item)