MM-49083 Disable write timeouts for exports (#22035)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
46d85ea910
Коммит
51ac81d816
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) {
|
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.
|
// Check if we can provide a custom context, otherwise just use the default method.
|
||||||
if cw, ok := fileBackend.(ContextWriter); ok {
|
written, err := filestore.TryWriteFileContext(s.FileBackend(), ctx, fr, path)
|
||||||
written, err = cw.WriteFileContext(ctx, fr, path)
|
|
||||||
} else {
|
|
||||||
written, err = fileBackend.WriteFile(fr, path)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return written, model.NewAppError("WriteFile", "api.file.write_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
return written, model.NewAppError("WriteFile", "api.file.write_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package filestore
|
package filestore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -84,3 +85,18 @@ func NewFileBackend(settings FileBackendSettings) (FileBackend, error) {
|
|||||||
}
|
}
|
||||||
return nil, errors.New("no valid filestorage driver found")
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user