From bec3a327a7a670456587739850ce93c38add3912 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Sat, 17 Sep 2022 15:31:30 +0800 Subject: [PATCH] fix: hide objs if only virtual files --- internal/fs/list.go | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/internal/fs/list.go b/internal/fs/list.go index d5800bc9763..8a0ad0c35ce 100644 --- a/internal/fs/list.go +++ b/internal/fs/list.go @@ -16,37 +16,43 @@ import ( func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) { meta := ctx.Value("meta").(*model.Meta) user := ctx.Value("user").(*model.User) + var objs []model.Obj storage, actualPath, err := op.GetStorageAndActualPath(path) virtualFiles := op.GetStorageVirtualFilesByPath(path) if err != nil { - if len(virtualFiles) != 0 { - return virtualFiles, nil + if len(virtualFiles) == 0 { + return nil, errors.WithMessage(err, "failed get storage") } - return nil, errors.WithMessage(err, "failed get storage") - } - objs, err := op.List(ctx, storage, actualPath, model.ListArgs{ - ReqPath: path, - }, refresh...) - if err != nil { - log.Errorf("%+v", err) - if len(virtualFiles) != 0 { - return virtualFiles, nil + } else { + objs, err = op.List(ctx, storage, actualPath, model.ListArgs{ + ReqPath: path, + }, refresh...) + if err != nil { + log.Errorf("%+v", err) + if len(virtualFiles) == 0 { + return nil, errors.WithMessage(err, "failed get objs") + } } - return nil, errors.WithMessage(err, "failed get objs") } - for _, storageFile := range virtualFiles { - if !containsByName(objs, storageFile) { - objs = append(objs, storageFile) + if objs == nil { + objs = virtualFiles + } else { + for _, storageFile := range virtualFiles { + if !containsByName(objs, storageFile) { + objs = append(objs, storageFile) + } } } if whetherHide(user, meta, path) { objs = hide(objs, meta) } // sort objs - if storage.Config().LocalSort { - model.SortFiles(objs, storage.GetStorage().OrderBy, storage.GetStorage().OrderDirection) + if storage != nil { + if storage.Config().LocalSort { + model.SortFiles(objs, storage.GetStorage().OrderBy, storage.GetStorage().OrderDirection) + } + model.ExtractFolder(objs, storage.GetStorage().ExtractFolder) } - model.ExtractFolder(objs, storage.GetStorage().ExtractFolder) return objs, nil }