From 29fe49fb872561df7c73dc89b29ce3e2b359a631 Mon Sep 17 00:00:00 2001 From: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:59:10 +0800 Subject: [PATCH] fix(alias): Support forced refresh of file list (#6562) --- drivers/alias/driver.go | 3 ++- drivers/alias/util.go | 40 ++++++++++++++++++++-------------------- internal/fs/list.go | 3 ++- internal/model/args.go | 1 + internal/op/fs.go | 4 ++-- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/drivers/alias/driver.go b/drivers/alias/driver.go index d9b290edc65..1b439a2c9d9 100644 --- a/drivers/alias/driver.go +++ b/drivers/alias/driver.go @@ -91,8 +91,9 @@ func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([ return nil, errs.ObjectNotFound } var objs []model.Obj + fsArgs := &fs.ListArgs{NoLog: true, Refresh: args.Refresh} for _, dst := range dsts { - tmp, err := d.list(ctx, dst, sub) + tmp, err := d.list(ctx, dst, sub, fsArgs) if err == nil { objs = append(objs, tmp...) } diff --git a/drivers/alias/util.go b/drivers/alias/util.go index ba1f7e72649..c0e9081b0fc 100644 --- a/drivers/alias/util.go +++ b/drivers/alias/util.go @@ -16,7 +16,7 @@ import ( func (d *Alias) listRoot() []model.Obj { var objs []model.Obj - for k, _ := range d.pathMap { + for k := range d.pathMap { obj := model.Object{ Name: k, IsFolder: true, @@ -65,8 +65,8 @@ func (d *Alias) get(ctx context.Context, path string, dst, sub string) (model.Ob }, nil } -func (d *Alias) list(ctx context.Context, dst, sub string) ([]model.Obj, error) { - objs, err := fs.List(ctx, stdpath.Join(dst, sub), &fs.ListArgs{NoLog: true}) +func (d *Alias) list(ctx context.Context, dst, sub string, args *fs.ListArgs) ([]model.Obj, error) { + objs, err := fs.List(ctx, stdpath.Join(dst, sub), args) // the obj must implement the model.SetPath interface // return objs, err if err != nil { @@ -120,32 +120,32 @@ func (d *Alias) link(ctx context.Context, dst, sub string, args model.LinkArgs) func (d *Alias) getReqPath(ctx context.Context, obj model.Obj) (*string, error) { root, sub := d.getRootAndPath(obj.GetPath()) - if sub == "" || sub == "/" { + if sub == "" { return nil, errs.NotSupport } dsts, ok := d.pathMap[root] if !ok { return nil, errs.ObjectNotFound } - var reqPath string - var err error + var reqPath *string for _, dst := range dsts { - reqPath = stdpath.Join(dst, sub) - _, err = fs.Get(ctx, reqPath, &fs.GetArgs{NoLog: true}) - if err == nil { - if d.ProtectSameName { - if ok { - ok = false - } else { - return nil, errs.NotImplement - } - } else { - break - } + path := stdpath.Join(dst, sub) + _, err := fs.Get(ctx, path, &fs.GetArgs{NoLog: true}) + if err != nil { + continue } + if !d.ProtectSameName { + return &path, nil + } + if ok { + ok = false + } else { + return nil, errs.NotImplement + } + reqPath = &path } - if err != nil { + if reqPath == nil { return nil, errs.ObjectNotFound } - return &reqPath, nil + return reqPath, nil } diff --git a/internal/fs/list.go b/internal/fs/list.go index 6e257cea6fa..d4f59cb829f 100644 --- a/internal/fs/list.go +++ b/internal/fs/list.go @@ -24,7 +24,8 @@ func list(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error) if storage != nil { _objs, err = op.List(ctx, storage, actualPath, model.ListArgs{ ReqPath: path, - }, args.Refresh) + Refresh: args.Refresh, + }) if err != nil { if !args.NoLog { log.Errorf("fs/list: %+v", err) diff --git a/internal/model/args.go b/internal/model/args.go index ac3c1875bfa..613699b95b4 100644 --- a/internal/model/args.go +++ b/internal/model/args.go @@ -13,6 +13,7 @@ import ( type ListArgs struct { ReqPath string S3ShowPlaceholder bool + Refresh bool } type LinkArgs struct { diff --git a/internal/op/fs.go b/internal/op/fs.go index 4f0cbbdd3ae..5c9c9f3f138 100644 --- a/internal/op/fs.go +++ b/internal/op/fs.go @@ -100,14 +100,14 @@ func Key(storage driver.Driver, path string) string { } // List files in storage, not contains virtual file -func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs, refresh ...bool) ([]model.Obj, error) { +func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs) ([]model.Obj, error) { if storage.Config().CheckStatus && storage.GetStorage().Status != WORK { return nil, errors.Errorf("storage not init: %s", storage.GetStorage().Status) } path = utils.FixAndCleanPath(path) log.Debugf("op.List %s", path) key := Key(storage, path) - if !utils.IsBool(refresh...) { + if !args.Refresh { if files, ok := listCache.Get(key); ok { log.Debugf("use cache when list %s", path) return files, nil