Skip to content

Commit

Permalink
fix(artifact): fix minio "get file by path" (#116)
Browse files Browse the repository at this point in the history
Because

there is a random output of minIO

This commit

add index for concurrent requests
  • Loading branch information
Yougigun authored Oct 15, 2024
1 parent b612e82 commit 25cf426
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func (m *Minio) GetFile(ctx context.Context, filePathName string) ([]byte, error

// FileContent represents a file and its content
type FileContent struct {
Index int
Name string
Content []byte
}
Expand All @@ -218,10 +219,10 @@ func (m *Minio) GetFilesByPaths(ctx context.Context, filePaths []string) ([]File
fileCh := make(chan FileContent, len(filePaths))
errorCh := make(chan error, len(filePaths))

for _, path := range filePaths {
for i, path := range filePaths {
wg.Add(1)
go utils.GoRecover(func() {
func(filePath string) {
func(i int, filePath string) {
defer wg.Done()
var obj *minio.Object
var err error
Expand All @@ -248,20 +249,21 @@ func (m *Minio) GetFilesByPaths(ctx context.Context, filePaths []string) ([]File
return
}
fileCh <- FileContent{
Index: i,
Name: filepath.Base(filePath),
Content: buffer.Bytes(),
}
}(path)
}(i, path)
}, fmt.Sprintf("GetFilesByPaths %s", path))
}

wg.Wait()
close(fileCh)
close(errorCh)

var files []FileContent
files := make([]FileContent, len(filePaths))
for file := range fileCh {
files = append(files, file)
files[file.Index] = file
}

// Check if any errors occurred
Expand Down

0 comments on commit 25cf426

Please sign in to comment.