mirror of https://github.com/Xhofe/alist
fix(alias): Support forced refresh of file list (#6562)
parent
fcf2683112
commit
29fe49fb87
|
@ -91,8 +91,9 @@ func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
|
||||||
return nil, errs.ObjectNotFound
|
return nil, errs.ObjectNotFound
|
||||||
}
|
}
|
||||||
var objs []model.Obj
|
var objs []model.Obj
|
||||||
|
fsArgs := &fs.ListArgs{NoLog: true, Refresh: args.Refresh}
|
||||||
for _, dst := range dsts {
|
for _, dst := range dsts {
|
||||||
tmp, err := d.list(ctx, dst, sub)
|
tmp, err := d.list(ctx, dst, sub, fsArgs)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
objs = append(objs, tmp...)
|
objs = append(objs, tmp...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
|
|
||||||
func (d *Alias) listRoot() []model.Obj {
|
func (d *Alias) listRoot() []model.Obj {
|
||||||
var objs []model.Obj
|
var objs []model.Obj
|
||||||
for k, _ := range d.pathMap {
|
for k := range d.pathMap {
|
||||||
obj := model.Object{
|
obj := model.Object{
|
||||||
Name: k,
|
Name: k,
|
||||||
IsFolder: true,
|
IsFolder: true,
|
||||||
|
@ -65,8 +65,8 @@ func (d *Alias) get(ctx context.Context, path string, dst, sub string) (model.Ob
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Alias) list(ctx context.Context, dst, sub string) ([]model.Obj, error) {
|
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), &fs.ListArgs{NoLog: true})
|
objs, err := fs.List(ctx, stdpath.Join(dst, sub), args)
|
||||||
// the obj must implement the model.SetPath interface
|
// the obj must implement the model.SetPath interface
|
||||||
// return objs, err
|
// return objs, err
|
||||||
if err != nil {
|
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) {
|
func (d *Alias) getReqPath(ctx context.Context, obj model.Obj) (*string, error) {
|
||||||
root, sub := d.getRootAndPath(obj.GetPath())
|
root, sub := d.getRootAndPath(obj.GetPath())
|
||||||
if sub == "" || sub == "/" {
|
if sub == "" {
|
||||||
return nil, errs.NotSupport
|
return nil, errs.NotSupport
|
||||||
}
|
}
|
||||||
dsts, ok := d.pathMap[root]
|
dsts, ok := d.pathMap[root]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errs.ObjectNotFound
|
return nil, errs.ObjectNotFound
|
||||||
}
|
}
|
||||||
var reqPath string
|
var reqPath *string
|
||||||
var err error
|
|
||||||
for _, dst := range dsts {
|
for _, dst := range dsts {
|
||||||
reqPath = stdpath.Join(dst, sub)
|
path := stdpath.Join(dst, sub)
|
||||||
_, err = fs.Get(ctx, reqPath, &fs.GetArgs{NoLog: true})
|
_, err := fs.Get(ctx, path, &fs.GetArgs{NoLog: true})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
if d.ProtectSameName {
|
continue
|
||||||
if ok {
|
|
||||||
ok = false
|
|
||||||
} else {
|
|
||||||
return nil, errs.NotImplement
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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 nil, errs.ObjectNotFound
|
||||||
}
|
}
|
||||||
return &reqPath, nil
|
return reqPath, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ func list(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error)
|
||||||
if storage != nil {
|
if storage != nil {
|
||||||
_objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
|
_objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
|
||||||
ReqPath: path,
|
ReqPath: path,
|
||||||
}, args.Refresh)
|
Refresh: args.Refresh,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !args.NoLog {
|
if !args.NoLog {
|
||||||
log.Errorf("fs/list: %+v", err)
|
log.Errorf("fs/list: %+v", err)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
type ListArgs struct {
|
type ListArgs struct {
|
||||||
ReqPath string
|
ReqPath string
|
||||||
S3ShowPlaceholder bool
|
S3ShowPlaceholder bool
|
||||||
|
Refresh bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type LinkArgs struct {
|
type LinkArgs struct {
|
||||||
|
|
|
@ -100,14 +100,14 @@ func Key(storage driver.Driver, path string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// List files in storage, not contains virtual file
|
// 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 {
|
if storage.Config().CheckStatus && storage.GetStorage().Status != WORK {
|
||||||
return nil, errors.Errorf("storage not init: %s", storage.GetStorage().Status)
|
return nil, errors.Errorf("storage not init: %s", storage.GetStorage().Status)
|
||||||
}
|
}
|
||||||
path = utils.FixAndCleanPath(path)
|
path = utils.FixAndCleanPath(path)
|
||||||
log.Debugf("op.List %s", path)
|
log.Debugf("op.List %s", path)
|
||||||
key := Key(storage, path)
|
key := Key(storage, path)
|
||||||
if !utils.IsBool(refresh...) {
|
if !args.Refresh {
|
||||||
if files, ok := listCache.Get(key); ok {
|
if files, ok := listCache.Get(key); ok {
|
||||||
log.Debugf("use cache when list %s", path)
|
log.Debugf("use cache when list %s", path)
|
||||||
return files, nil
|
return files, nil
|
||||||
|
|
Loading…
Reference in New Issue