@@ -8,15 +8,14 @@ import (
8
8
"encoding/base64"
9
9
"fmt"
10
10
"io"
11
+ "path"
11
12
"path/filepath"
12
13
"sort"
13
- "strings"
14
14
"time"
15
15
16
16
"code.gitea.io/gitea/models/actions"
17
17
"code.gitea.io/gitea/models/db"
18
18
"code.gitea.io/gitea/modules/log"
19
- "code.gitea.io/gitea/modules/setting"
20
19
"code.gitea.io/gitea/modules/storage"
21
20
)
22
21
@@ -32,7 +31,7 @@ func saveUploadChunk(st storage.ObjectStorage, ctx *ArtifactContext,
32
31
return - 1 , fmt .Errorf ("parse content range error: %v" , err )
33
32
}
34
33
// build chunk store path
35
- storagePath := fmt .Sprintf ("tmp%d/%d-%d-%d.chunk" , runID , artifact .ID , start , end )
34
+ storagePath := fmt .Sprintf ("tmp%d/%d-%d-%d-%d .chunk" , runID , runID , artifact .ID , start , end )
36
35
// use io.TeeReader to avoid reading all body to md5 sum.
37
36
// it writes data to hasher after reading end
38
37
// if hash is not matched, delete the read-end result
@@ -61,24 +60,22 @@ func saveUploadChunk(st storage.ObjectStorage, ctx *ArtifactContext,
61
60
}
62
61
63
62
type chunkFileItem struct {
63
+ RunID int64
64
64
ArtifactID int64
65
65
Start int64
66
66
End int64
67
67
Path string
68
68
}
69
69
70
- func listChunksByRunID (st storage.ObjectStorage , runID int64 , basepath string ) (map [int64 ][]* chunkFileItem , error ) {
70
+ func listChunksByRunID (st storage.ObjectStorage , runID int64 ) (map [int64 ][]* chunkFileItem , error ) {
71
71
storageDir := fmt .Sprintf ("tmp%d" , runID )
72
72
var chunks []* chunkFileItem
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
- }
80
- item := chunkFileItem {Path : path }
81
- if _ , err := fmt .Sscanf (path , filepath .Join (storageDir , "%d-%d-%d.chunk" ), & item .ArtifactID , & item .Start , & item .End ); err != nil {
73
+ if err := st .IterateObjects (storageDir , func (fpath string , obj storage.Object ) error {
74
+ baseName := filepath .Base (fpath )
75
+ // when read chunks from storage, it only contains storage dir and basename,
76
+ // no matter the subdirectory setting in storage config
77
+ item := chunkFileItem {Path : path .Join (storageDir , baseName )}
78
+ if _ , err := fmt .Sscanf (baseName , "%d-%d-%d-%d.chunk" , & item .RunID , & item .ArtifactID , & item .Start , & item .End ); err != nil {
82
79
return fmt .Errorf ("parse content range error: %v" , err )
83
80
}
84
81
chunks = append (chunks , & item )
@@ -103,11 +100,8 @@ func mergeChunksForRun(ctx *ArtifactContext, st storage.ObjectStorage, runID int
103
100
if err != nil {
104
101
return err
105
102
}
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
109
103
// read all uploading chunks from storage
110
- chunksMap , err := listChunksByRunID (st , runID , basepath )
104
+ chunksMap , err := listChunksByRunID (st , runID )
111
105
if err != nil {
112
106
return err
113
107
}
0 commit comments