mirror of https://github.com/harness/drone.git
fix: [CODE-3455] return full content on raw api for non-lfs content (#3625)
parent
39a70ea02e
commit
3c22d6342a
|
@ -15,6 +15,7 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -33,6 +34,15 @@ type RawContent struct {
|
|||
SHA sha.SHA
|
||||
}
|
||||
|
||||
type multiReadCloser struct {
|
||||
io.Reader
|
||||
closeFunc func() error
|
||||
}
|
||||
|
||||
func (m *multiReadCloser) Close() error {
|
||||
return m.closeFunc()
|
||||
}
|
||||
|
||||
// Raw finds the file of the repo at the given path and returns its raw content.
|
||||
// If no gitRef is provided, the content is retrieved from the default branch.
|
||||
func (c *Controller) Raw(ctx context.Context,
|
||||
|
@ -79,7 +89,7 @@ func (c *Controller) Raw(ctx context.Context,
|
|||
return nil, fmt.Errorf("failed to read blob: %w", err)
|
||||
}
|
||||
|
||||
// check if blob is LFS
|
||||
// check if blob is an LFS pointer
|
||||
content, err := io.ReadAll(io.LimitReader(blobReader.Content, parser.LfsPointerMaxSize))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read LFS file content: %w", err)
|
||||
|
@ -88,7 +98,10 @@ func (c *Controller) Raw(ctx context.Context,
|
|||
lfsInfo, ok := parser.IsLFSPointer(ctx, content, blobReader.Size)
|
||||
if !ok {
|
||||
return &RawContent{
|
||||
Data: blobReader.Content,
|
||||
Data: &multiReadCloser{
|
||||
Reader: io.MultiReader(bytes.NewBuffer(content), blobReader.Content),
|
||||
closeFunc: blobReader.Content.Close,
|
||||
},
|
||||
Size: blobReader.ContentSize,
|
||||
SHA: blobReader.SHA,
|
||||
}, nil
|
||||
|
|
Loading…
Reference in New Issue