mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-02 11:57:04 +08:00
fix (s3): stop condition for recursive ls in s3
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package plg_backend_s3
|
package plg_backend_s3
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
@ -16,14 +17,16 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var S3Cache AppCache
|
var S3Cache AppCache
|
||||||
|
|
||||||
type S3Backend struct {
|
type S3Backend struct {
|
||||||
client *s3.S3
|
client *s3.S3
|
||||||
config *aws.Config
|
config *aws.Config
|
||||||
params map[string]string
|
params map[string]string
|
||||||
|
context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -63,9 +66,10 @@ func (s S3Backend) Init(params map[string]string, app *App) (IBackend, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
backend := &S3Backend{
|
backend := &S3Backend{
|
||||||
config: config,
|
config: config,
|
||||||
params: params,
|
params: params,
|
||||||
client: s3.New(session.New(config)),
|
client: s3.New(session.New(config)),
|
||||||
|
context: app.Context,
|
||||||
}
|
}
|
||||||
return backend, nil
|
return backend, nil
|
||||||
}
|
}
|
||||||
@ -161,7 +165,9 @@ func (s S3Backend) Ls(path string) (files []os.FileInfo, err error) {
|
|||||||
}
|
}
|
||||||
client := s3.New(s.createSession(p.bucket))
|
client := s3.New(s.createSession(p.bucket))
|
||||||
|
|
||||||
err = client.ListObjectsV2Pages(
|
startTime := time.Now()
|
||||||
|
err = client.ListObjectsV2PagesWithContext(
|
||||||
|
s.context,
|
||||||
&s3.ListObjectsV2Input{
|
&s3.ListObjectsV2Input{
|
||||||
Bucket: aws.String(p.bucket),
|
Bucket: aws.String(p.bucket),
|
||||||
Prefix: aws.String(p.path),
|
Prefix: aws.String(p.path),
|
||||||
@ -185,7 +191,7 @@ func (s S3Backend) Ls(path string) (files []os.FileInfo, err error) {
|
|||||||
FType: "directory",
|
FType: "directory",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return true
|
return time.Since(startTime) < 5*time.Second
|
||||||
})
|
})
|
||||||
return files, err
|
return files, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user