mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-49083 Disable write timeouts for exports (#22035)
This commit is contained in:
16
app/file.go
16
app/file.go
@@ -178,22 +178,8 @@ func (s *Server) writeFile(fr io.Reader, path string) (int64, *model.AppError) {
|
||||
}
|
||||
|
||||
func (s *Server) writeFileContext(ctx context.Context, fr io.Reader, path string) (int64, *model.AppError) {
|
||||
type ContextWriter interface {
|
||||
WriteFileContext(context.Context, io.Reader, string) (int64, error)
|
||||
}
|
||||
|
||||
var (
|
||||
fileBackend = s.FileBackend()
|
||||
written int64
|
||||
err error
|
||||
)
|
||||
|
||||
// Check if we can provide a custom context, otherwise just use the default method.
|
||||
if cw, ok := fileBackend.(ContextWriter); ok {
|
||||
written, err = cw.WriteFileContext(ctx, fr, path)
|
||||
} else {
|
||||
written, err = fileBackend.WriteFile(fr, path)
|
||||
}
|
||||
written, err := filestore.TryWriteFileContext(s.FileBackend(), ctx, fr, path)
|
||||
if err != nil {
|
||||
return written, model.NewAppError("WriteFile", "api.file.write_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package filestore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
@@ -84,3 +85,18 @@ func NewFileBackend(settings FileBackendSettings) (FileBackend, error) {
|
||||
}
|
||||
return nil, errors.New("no valid filestorage driver found")
|
||||
}
|
||||
|
||||
// TryWriteFileContext checks if the file backend supports context writes and passes the context in that case.
|
||||
// Should the file backend not support contexts, it just calls WriteFile instead. This can be used to disable
|
||||
// the timeouts for long writes (like exports).
|
||||
func TryWriteFileContext(fb FileBackend, ctx context.Context, fr io.Reader, path string) (int64, error) {
|
||||
type ContextWriter interface {
|
||||
WriteFileContext(context.Context, io.Reader, string) (int64, error)
|
||||
}
|
||||
|
||||
if cw, ok := fb.(ContextWriter); ok {
|
||||
return cw.WriteFileContext(ctx, fr, path)
|
||||
}
|
||||
|
||||
return fb.WriteFile(fr, path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user