diff --git a/server/plugin/plg_backend_s3/index.go b/server/plugin/plg_backend_s3/index.go index e3e767485..ffa7bb73b 100644 --- a/server/plugin/plg_backend_s3/index.go +++ b/server/plugin/plg_backend_s3/index.go @@ -30,7 +30,7 @@ type S3Backend struct { client *s3.S3 config *aws.Config params map[string]string - context context.Context + Context context.Context threadSize int } @@ -89,7 +89,7 @@ func (this S3Backend) Init(params map[string]string, app *App) (IBackend, error) config: config, params: params, client: s3.New(session.New(config)), - context: app.Context, + Context: app.Context, threadSize: threadSize, } return backend, nil @@ -200,7 +200,7 @@ func (this S3Backend) Ls(path string) (files []os.FileInfo, err error) { } client := s3.New(this.createSession(p.bucket)) err = client.ListObjectsV2PagesWithContext( - this.context, + this.Context, &s3.ListObjectsV2Input{ Bucket: aws.String(p.bucket), Prefix: aws.String(p.path), @@ -295,7 +295,7 @@ func (this S3Backend) Rm(path string) error { // CASE 2: remove a folder jobChan := make(chan S3Path, this.threadSize) errChan := make(chan error, this.threadSize) - ctx, cancel := context.WithCancel(this.context) + ctx, cancel := context.WithCancel(this.Context) var wg sync.WaitGroup for i := 1; i <= this.threadSize; i++ { wg.Add(1) @@ -316,7 +316,7 @@ func (this S3Backend) Rm(path string) error { }() } err := client.ListObjectsV2PagesWithContext( - this.context, + this.Context, &s3.ListObjectsV2Input{ Bucket: aws.String(p.bucket), Prefix: aws.String(p.path), @@ -387,7 +387,7 @@ func (this S3Backend) Mv(from string, to string) error { // CASE 3: Rename/Move a folder jobChan := make(chan []S3Path, this.threadSize) errChan := make(chan error, this.threadSize) - ctx, cancel := context.WithCancel(this.context) + ctx, cancel := context.WithCancel(this.Context) var wg sync.WaitGroup for i := 1; i <= this.threadSize; i++ { wg.Add(1) @@ -427,7 +427,7 @@ func (this S3Backend) Mv(from string, to string) error { }() } err := client.ListObjectsV2PagesWithContext( - this.context, + this.Context, &s3.ListObjectsV2Input{ Bucket: aws.String(f.bucket), Prefix: aws.String(f.path), diff --git a/server/plugin/plg_search_sqlitefts/crawlstate.go b/server/plugin/plg_search_sqlitefts/crawlstate.go index d14d8087b..69f54126e 100644 --- a/server/plugin/plg_search_sqlitefts/crawlstate.go +++ b/server/plugin/plg_search_sqlitefts/crawlstate.go @@ -2,9 +2,12 @@ package plg_search_sqlitefts import ( "container/heap" - . "github.com/mickael-kerjean/filestash/server/common" + "context" "path/filepath" + "reflect" "sync" + + . "github.com/mickael-kerjean/filestash/server/common" ) var SProc SearchProcess = SearchProcess{ @@ -60,6 +63,13 @@ func (this *SearchProcess) HintLs(app *App, path string) *SearchIndexer { } // instantiate the new indexer s := NewSearchIndexer(id, app.Backend) + v := reflect.ValueOf(app.Backend).Elem().FieldByName("Context") + if v.IsValid() && v.CanSet() { + // prevent context expiration which is often default as r.Context() + // as we need to make queries outside the scope of a normal http request + v.Set(reflect.ValueOf(context.Background())) + } + heap.Push(&s.FoldersUnknown, &Document{ Type: "directory", Path: path,