MM-50419: Fix panic at interface conversion (#22284)
We were incorrectly returning a subset of the methods, whereas at other places, clients needed access to other interfaces as well. https://mattermost.atlassian.net/browse/MM-50419 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e325f3fa1c
Коммит
0880837fd0
@@ -57,6 +57,11 @@ var (
|
|||||||
imageMimeTypes = map[string]string{".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".bmp": "image/bmp", ".png": "image/png", ".tiff": "image/tiff", ".tif": "image/tif"}
|
imageMimeTypes = map[string]string{".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".bmp": "image/bmp", ".png": "image/png", ".tiff": "image/tiff", ".tif": "image/tif"}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Ensure that the ReaderAt interface is implemented.
|
||||||
|
_ io.ReaderAt = (*s3WithCancel)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
func isFileExtImage(ext string) bool {
|
func isFileExtImage(ext string) bool {
|
||||||
ext = strings.ToLower(ext)
|
ext = strings.ToLower(ext)
|
||||||
return imageExtensions[ext]
|
return imageExtensions[ext]
|
||||||
@@ -208,7 +213,7 @@ func (b *S3FileBackend) MakeBucket() error {
|
|||||||
// s3WithCancel is a wrapper struct which cancels the context
|
// s3WithCancel is a wrapper struct which cancels the context
|
||||||
// when the object is closed.
|
// when the object is closed.
|
||||||
type s3WithCancel struct {
|
type s3WithCancel struct {
|
||||||
io.ReadSeekCloser
|
*s3.Object
|
||||||
timer *time.Timer
|
timer *time.Timer
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
@@ -216,7 +221,7 @@ type s3WithCancel struct {
|
|||||||
func (sc *s3WithCancel) Close() error {
|
func (sc *s3WithCancel) Close() error {
|
||||||
sc.timer.Stop()
|
sc.timer.Stop()
|
||||||
sc.cancel()
|
sc.cancel()
|
||||||
return sc.ReadSeekCloser.Close()
|
return sc.Object.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancelTimeout attempts to cancel the timeout for this reader. It allows calling
|
// CancelTimeout attempts to cancel the timeout for this reader. It allows calling
|
||||||
@@ -237,9 +242,9 @@ func (b *S3FileBackend) Reader(path string) (ReadCloseSeeker, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sc := &s3WithCancel{
|
sc := &s3WithCancel{
|
||||||
ReadSeekCloser: minioObject,
|
Object: minioObject,
|
||||||
timer: time.AfterFunc(b.timeout, cancel),
|
timer: time.AfterFunc(b.timeout, cancel),
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sc, nil
|
return sc, nil
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -19,6 +18,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
s3 "github.com/minio/minio-go/v7"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -283,20 +283,25 @@ func TestS3WithCancel(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMockS3WithCancel(timeout time.Duration, closeErr error) (*s3WithCancel, context.Context) {
|
func newMockS3WithCancel(timeout time.Duration, closeErr error) (*fauxCloser, context.Context) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
return &s3WithCancel{
|
return &fauxCloser{
|
||||||
ReadSeekCloser: fauxCloser{strings.NewReader("testdata"), closeErr},
|
s3WithCancel: &s3WithCancel{
|
||||||
timer: time.AfterFunc(timeout, cancel),
|
Object: &s3.Object{},
|
||||||
cancel: cancel,
|
timer: time.AfterFunc(timeout, cancel),
|
||||||
|
cancel: cancel,
|
||||||
|
},
|
||||||
|
closeErr: closeErr,
|
||||||
}, ctx
|
}, ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
type fauxCloser struct {
|
type fauxCloser struct {
|
||||||
io.ReadSeeker
|
*s3WithCancel
|
||||||
closeErr error
|
closeErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc fauxCloser) Close() error {
|
func (fc fauxCloser) Close() error {
|
||||||
|
fc.s3WithCancel.timer.Stop()
|
||||||
|
fc.s3WithCancel.cancel()
|
||||||
return fc.closeErr
|
return fc.closeErr
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user