@@ -10,11 +10,13 @@ import (
10
10
"io"
11
11
"path/filepath"
12
12
"sort"
13
+ "strings"
13
14
"time"
14
15
15
16
"code.gitea.io/gitea/models/actions"
16
17
"code.gitea.io/gitea/models/db"
17
18
"code.gitea.io/gitea/modules/log"
19
+ "code.gitea.io/gitea/modules/setting"
18
20
"code.gitea.io/gitea/modules/storage"
19
21
)
20
22
@@ -26,6 +28,7 @@ func saveUploadChunk(st storage.ObjectStorage, ctx *ArtifactContext,
26
28
contentRange := ctx .Req .Header .Get ("Content-Range" )
27
29
start , end , length := int64 (0 ), int64 (0 ), int64 (0 )
28
30
if _ , err := fmt .Sscanf (contentRange , "bytes %d-%d/%d" , & start , & end , & length ); err != nil {
31
+ log .Warn ("parse content range error: %v, content-range: %s" , err , contentRange )
29
32
return - 1 , fmt .Errorf ("parse content range error: %v" , err )
30
33
}
31
34
// build chunk store path
@@ -64,10 +67,16 @@ type chunkFileItem struct {
64
67
Path string
65
68
}
66
69
67
- func listChunksByRunID (st storage.ObjectStorage , runID int64 ) (map [int64 ][]* chunkFileItem , error ) {
70
+ func listChunksByRunID (st storage.ObjectStorage , runID int64 , basepath string ) (map [int64 ][]* chunkFileItem , error ) {
68
71
storageDir := fmt .Sprintf ("tmp%d" , runID )
69
72
var chunks []* chunkFileItem
70
73
if err := st .IterateObjects (storageDir , func (path string , obj storage.Object ) error {
74
+ // if basepath is settings.Actions.ArtifactStorage.MinioConfig.BasePath, it should trim it
75
+ if basepath != "" {
76
+ log .Debug ("listChunksByRunID, trim basepath: %s, path: %s" , basepath , path )
77
+ basepath = strings .TrimPrefix (basepath , "/" )
78
+ path = strings .TrimPrefix (path , basepath + "/" )
79
+ }
71
80
item := chunkFileItem {Path : path }
72
81
if _ , err := fmt .Sscanf (path , filepath .Join (storageDir , "%d-%d-%d.chunk" ), & item .ArtifactID , & item .Start , & item .End ); err != nil {
73
82
return fmt .Errorf ("parse content range error: %v" , err )
@@ -94,8 +103,11 @@ func mergeChunksForRun(ctx *ArtifactContext, st storage.ObjectStorage, runID int
94
103
if err != nil {
95
104
return err
96
105
}
106
+ // if use minio, it should trim basepath when iterate objects for chunks
107
+ // if use local, basepath is empty
108
+ basepath := setting .Actions .ArtifactStorage .MinioConfig .BasePath
97
109
// read all uploading chunks from storage
98
- chunksMap , err := listChunksByRunID (st , runID )
110
+ chunksMap , err := listChunksByRunID (st , runID , basepath )
99
111
if err != nil {
100
112
return err
101
113
}
0 commit comments