Skip to content

Commit

Permalink
feat: get root folder file
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 13, 2022
1 parent 3135775 commit 3e8f36e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
24 changes: 20 additions & 4 deletions internal/fs/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/utils/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 3e8f36e

Please sign in to comment.