Skip to content

Commit

Permalink
feat: dir and file check
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 23, 2022
1 parent d77dea7 commit b971b13
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
14 changes: 3 additions & 11 deletions internal/errs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@ package errs

import (
"errors"
pkgerr "github.com/pkg/errors"
)

var (
ObjectNotFound = errors.New("object not found")
NotImplement = errors.New("not implement")
NotSupport = errors.New("not support")
RelativePath = errors.New("access using relative path is not allowed")
NotImplement = errors.New("not implement")
NotSupport = errors.New("not support")
RelativePath = errors.New("access using relative path is not allowed")

MoveBetweenTwoAccounts = errors.New("can't move files between two account, try to copy")
UploadNotSupported = errors.New("upload not supported")
NotFolder = errors.New("not a folder")
NotFile = errors.New("not a file")

MetaNotFound = errors.New("meta not found")
)

func IsObjectNotFound(err error) bool {
return pkgerr.Cause(err) == ObjectNotFound
}
16 changes: 16 additions & 0 deletions internal/errs/object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package errs

import (
"errors"
pkgerr "github.com/pkg/errors"
)

var (
ObjectNotFound = errors.New("object not found")
NotFolder = errors.New("not a folder")
NotFile = errors.New("not a file")
)

func IsObjectNotFound(err error) bool {
return pkgerr.Cause(err) == ObjectNotFound
}
3 changes: 3 additions & 0 deletions internal/operations/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func List(ctx context.Context, account driver.Driver, path string, refresh ...bo
if err != nil {
return nil, errors.WithMessage(err, "failed get dir")
}
if !dir.IsDir() {
return nil, errors.WithStack(errs.NotFolder)
}
if account.Config().NoCache {
return account.List(ctx, dir)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/operations/path.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package operations

import (
"github.com/alist-org/alist/v3/internal/errs"
stdpath "path"
"strings"

Expand All @@ -21,6 +22,9 @@ func ActualPath(account driver.Additional, rawPath string) string {
// for path: remove the virtual path prefix and join the actual root folder if exists
func GetAccountAndActualPath(rawPath string) (driver.Driver, string, error) {
rawPath = utils.StandardizationPath(rawPath)
if strings.Contains(rawPath, "..") {
return nil, "", errors.WithStack(errs.RelativePath)
}
account := GetBalancedAccount(rawPath)
if account == nil {
return nil, "", errors.Errorf("can't find account with rawPath: %s", rawPath)
Expand Down

0 comments on commit b971b13

Please sign in to comment.