mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2024-04-21 12:32:08 +00:00
fix (ls): configurable ls timeout for plugins
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package plg_backend_s3
|
||||
|
||||
import (
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ls_timeout func() time.Duration
|
||||
|
||||
func init() {
|
||||
ls_timeout = func() time.Duration {
|
||||
return time.Duration(Config.Get("features.protection.ls_timeout").Schema(func(f *FormElement) *FormElement {
|
||||
if f == nil {
|
||||
f = &FormElement{}
|
||||
}
|
||||
f.Default = 2
|
||||
f.Name = "ls_timeout"
|
||||
f.Type = "number"
|
||||
f.Target = []string{}
|
||||
f.Description = "failsafe timeout for listing files under a folder"
|
||||
f.Placeholder = "Default: 2"
|
||||
return f
|
||||
}).Int()) * time.Second
|
||||
}
|
||||
ls_timeout()
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var S3Cache AppCache
|
||||
@@ -169,6 +170,7 @@ func (s S3Backend) Ls(path string) (files []os.FileInfo, err error) {
|
||||
}
|
||||
client := s3.New(s.createSession(p.bucket))
|
||||
|
||||
startTime := time.Now()
|
||||
err = client.ListObjectsV2PagesWithContext(
|
||||
s.context,
|
||||
&s3.ListObjectsV2Input{
|
||||
@@ -194,6 +196,11 @@ func (s S3Backend) Ls(path string) (files []os.FileInfo, err error) {
|
||||
FType: "directory",
|
||||
})
|
||||
}
|
||||
|
||||
if time.Since(startTime) > ls_timeout() {
|
||||
Log.Debug("plg_backend_s3::ls timeout triggered after getting %d files", len(files))
|
||||
return false
|
||||
}
|
||||
return aws.BoolValue(objs.IsTruncated)
|
||||
})
|
||||
return files, err
|
||||
|
||||
Reference in New Issue
Block a user