Skip to content

Commit

Permalink
fix(alias): Support forced refresh of file list (#6562)
Browse files Browse the repository at this point in the history
  • Loading branch information
j2rong4cn authored Jun 16, 2024
1 parent fcf2683 commit 29fe49f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
3 changes: 2 additions & 1 deletion drivers/alias/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down
40 changes: 20 additions & 20 deletions drivers/alias/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion internal/fs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/model/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type ListArgs struct {
ReqPath string
S3ShowPlaceholder bool
Refresh bool
}

type LinkArgs struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/op/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29fe49f

Please sign in to comment.