Skip to content

Commit d28903a

Browse files
authored
fix(index): don't auto-index wrapper drivers' underlying storage (#9563)
Wrapper drivers (alias, crypt, strm, chunker) list their underlying storage via fs.List. Each such call went through op.List, which fires the objs-update hook that auto-builds the search index. As a result the underlying real path was indexed in addition to the wrapper's own mount path, so a file reached through an alias was indexed under both paths and showed up as duplicate search results when auto index build was on. Manual index build was unaffected because it indexes via an explicit tree walk while the update hook is disabled. Add a NoUpdateIndex flag to fs.ListArgs / model.ListArgs that skips the objs-update hook in op.List, and set it on the internal listing calls of all four wrapper drivers. The wrapper's own mount path is still indexed via its outer op.List call, and direct access to the underlying storage still indexes normally. Fixes #9489
1 parent 3fef207 commit d28903a

8 files changed

Lines changed: 23 additions & 10 deletions

File tree

drivers/alias/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
9292
return nil, errs.ObjectNotFound
9393
}
9494
var objs []model.Obj
95-
fsArgs := &fs.ListArgs{NoLog: true, Refresh: args.Refresh}
95+
fsArgs := &fs.ListArgs{NoLog: true, Refresh: args.Refresh, NoUpdateIndex: true}
9696
for _, dst := range dsts {
9797
tmp, err := d.list(ctx, dst, sub, fsArgs)
9898
if err == nil {

drivers/chunker/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,5 +900,5 @@ func (d *Chunker) openPartRange(ctx context.Context, link *model.Link, size, off
900900
}
901901

902902
func fsList(ctx context.Context, remotePath string, refresh bool) ([]model.Obj, error) {
903-
return fs.List(ctx, remotePath, &fs.ListArgs{NoLog: true, Refresh: refresh})
903+
return fs.List(ctx, remotePath, &fs.ListArgs{NoLog: true, Refresh: refresh, NoUpdateIndex: true})
904904
}

drivers/crypt/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (d *Crypt) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
110110
//return d.list(ctx, d.RemotePath, path)
111111
//remoteFull
112112

113-
objs, err := fs.List(ctx, d.getPathForRemote(path, true), &fs.ListArgs{NoLog: true})
113+
objs, err := fs.List(ctx, d.getPathForRemote(path, true), &fs.ListArgs{NoLog: true, NoUpdateIndex: true})
114114
// the obj must implement the model.SetPath interface
115115
// return objs, err
116116
if err != nil {

drivers/strm/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (d *Strm) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]
143143
out := make([]model.Obj, 0)
144144
for _, targetRoot := range targets {
145145
realDir := stdpath.Join(targetRoot, sub)
146-
objs, err := fs.List(ctx, realDir, &fs.ListArgs{NoLog: true, Refresh: args.Refresh})
146+
objs, err := fs.List(ctx, realDir, &fs.ListArgs{NoLog: true, Refresh: args.Refresh, NoUpdateIndex: true})
147147
if err != nil {
148148
continue
149149
}
@@ -188,7 +188,7 @@ func (d *Strm) rotateAllLocal(ctx context.Context) {
188188
}
189189

190190
func (d *Strm) walkAndSync(ctx context.Context, virtualDir, realDir string) {
191-
objs, err := fs.List(ctx, realDir, &fs.ListArgs{NoLog: true, Refresh: true})
191+
objs, err := fs.List(ctx, realDir, &fs.ListArgs{NoLog: true, Refresh: true, NoUpdateIndex: true})
192192
if err != nil {
193193
log.Warnf("strm: rotate list failed %s: %v", realDir, err)
194194
return

internal/fs/fs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
type ListArgs struct {
2121
Refresh bool
2222
NoLog bool
23+
// NoUpdateIndex skips the auto search-index update hook for this listing.
24+
// Wrapper drivers set it when listing their underlying storage so the real
25+
// path is not auto-indexed alongside the wrapper's mount path.
26+
NoUpdateIndex bool
2327
}
2428

2529
func List(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error) {

internal/fs/list.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ func list(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error)
2424
var _objs []model.Obj
2525
if storage != nil {
2626
_objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
27-
ReqPath: path,
28-
Refresh: args.Refresh,
27+
ReqPath: path,
28+
Refresh: args.Refresh,
29+
NoUpdateIndex: args.NoUpdateIndex,
2930
})
3031
if err != nil {
3132
if !args.NoLog {

internal/model/args.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ type ListArgs struct {
1414
ReqPath string
1515
S3ShowPlaceholder bool
1616
Refresh bool
17+
// NoUpdateIndex skips the objs-update hook (used to auto-build the search
18+
// index) for this listing. Wrapper drivers (alias, crypt, strm, chunker)
19+
// set it when listing their underlying storage so the real path is not
20+
// auto-indexed alongside the wrapper's own mount path, which would create
21+
// duplicate search entries.
22+
NoUpdateIndex bool
1723
}
1824

1925
type LinkArgs struct {

internal/op/fs.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ func List(ctx context.Context, storage driver.Driver, path string, args model.Li
143143
// warp obj name
144144
model.WrapObjsName(files)
145145
// call hooks
146-
go func(reqPath string, files []model.Obj) {
147-
HandleObjsUpdateHook(reqPath, files)
148-
}(utils.GetFullPath(storage.GetStorage().MountPath, path), files)
146+
if !args.NoUpdateIndex {
147+
go func(reqPath string, files []model.Obj) {
148+
HandleObjsUpdateHook(reqPath, files)
149+
}(utils.GetFullPath(storage.GetStorage().MountPath, path), files)
150+
}
149151

150152
// sort objs
151153
if storage.Config().LocalSort {

0 commit comments

Comments
 (0)