From 3e8f36e9f311d9a084436f9b7528f1c136ce438f Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Mon, 13 Jun 2022 14:53:44 +0800 Subject: [PATCH] feat: get root folder file --- internal/fs/read.go | 24 ++++++++++++++++++++---- pkg/utils/path.go | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/internal/fs/read.go b/internal/fs/read.go index 8354e4620d8..0eab1a02f26 100644 --- a/internal/fs/read.go +++ b/internal/fs/read.go @@ -3,10 +3,13 @@ package fs import ( "context" "github.com/alist-org/alist/v3/internal/driver" + "github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/pkg/utils" "github.com/pkg/errors" log "github.com/sirupsen/logrus" stdpath "path" + "time" ) // List files @@ -38,14 +41,27 @@ func List(ctx context.Context, path string) ([]driver.FileInfo, error) { } func Get(ctx context.Context, path string) (driver.FileInfo, error) { - virtualFiles := operations.GetAccountVirtualFilesByPath(path) - for _, f := range virtualFiles { - if f.GetName() == stdpath.Base(path) { - return f, nil + path = utils.StandardizationPath(path) + // maybe a virtual file + if path != "/" { + virtualFiles := operations.GetAccountVirtualFilesByPath(stdpath.Dir(path)) + for _, f := range virtualFiles { + if f.GetName() == stdpath.Base(path) { + return f, nil + } } } account, actualPath, err := operations.GetAccountAndActualPath(path) if err != nil { + // if there are no account prefix with path, maybe root folder + if path == "/" { + return model.File{ + Name: "root", + Size: 0, + Modified: time.Time{}, + IsFolder: true, + }, nil + } return nil, errors.WithMessage(err, "failed get account") } return operations.Get(ctx, account, actualPath) diff --git a/pkg/utils/path.go b/pkg/utils/path.go index a3fa9ed5b38..7c225c813e4 100644 --- a/pkg/utils/path.go +++ b/pkg/utils/path.go @@ -11,6 +11,7 @@ func StandardizationPath(path string) string { return path } +// PathEqual judge path is equal func PathEqual(path1, path2 string) bool { return StandardizationPath(path1) == StandardizationPath(path2) }