mirror of https://github.com/Xhofe/alist
				
				
				
			chore: rename errors
							parent
							
								
									fd5c3e831d
								
							
						
					
					
						commit
						d77dea733f
					
				| 
						 | 
				
			
			@ -20,7 +20,7 @@ func AddURI(ctx context.Context, uri string, dstDirPath string) error {
 | 
			
		|||
	}
 | 
			
		||||
	// check is it could upload
 | 
			
		||||
	if account.Config().NoUpload {
 | 
			
		||||
		return errors.WithStack(errs.ErrUploadNotSupported)
 | 
			
		||||
		return errors.WithStack(errs.UploadNotSupported)
 | 
			
		||||
	}
 | 
			
		||||
	// check path is valid
 | 
			
		||||
	obj, err := operations.Get(ctx, account, dstDirActualPath)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,16 +6,19 @@ import (
 | 
			
		|||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	ErrorObjectNotFound = errors.New("object not found")
 | 
			
		||||
	ErrNotImplement     = errors.New("not implement")
 | 
			
		||||
	ErrNotSupport       = errors.New("not support")
 | 
			
		||||
	ErrRelativePath     = errors.New("access using relative path is not allowed")
 | 
			
		||||
	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")
 | 
			
		||||
 | 
			
		||||
	ErrMoveBetweenTwoAccounts = errors.New("can't move files between two account, try to copy")
 | 
			
		||||
	ErrUploadNotSupported     = errors.New("upload not supported")
 | 
			
		||||
	ErrNotFolder              = errors.New("not a folder")
 | 
			
		||||
	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 IsErrObjectNotFound(err error) bool {
 | 
			
		||||
	return pkgerr.Cause(err) == ErrorObjectNotFound
 | 
			
		||||
func IsObjectNotFound(err error) bool {
 | 
			
		||||
	return pkgerr.Cause(err) == ObjectNotFound
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ var UploadTaskManager = task.NewTaskManager[uint64](3, func(tid *uint64) {
 | 
			
		|||
func Put(ctx context.Context, account driver.Driver, dstDirPath string, file model.FileStreamer) error {
 | 
			
		||||
	account, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
 | 
			
		||||
	if account.Config().NoUpload {
 | 
			
		||||
		return errors.WithStack(errs.ErrUploadNotSupported)
 | 
			
		||||
		return errors.WithStack(errs.UploadNotSupported)
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errors.WithMessage(err, "failed get account")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,7 @@ func Move(ctx context.Context, account driver.Driver, srcPath, dstDirPath string
 | 
			
		|||
		return errors.WithMessage(err, "failed get dst account")
 | 
			
		||||
	}
 | 
			
		||||
	if srcAccount.GetAccount() != dstAccount.GetAccount() {
 | 
			
		||||
		return errors.WithStack(errs.ErrMoveBetweenTwoAccounts)
 | 
			
		||||
		return errors.WithStack(errs.MoveBetweenTwoAccounts)
 | 
			
		||||
	}
 | 
			
		||||
	return operations.Move(ctx, account, srcActualPath, dstDirActualPath)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -86,7 +86,7 @@ func Get(ctx context.Context, account driver.Driver, path string) (model.Obj, er
 | 
			
		|||
			return f, nil
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil, errors.WithStack(errs.ErrorObjectNotFound)
 | 
			
		||||
	return nil, errors.WithStack(errs.ObjectNotFound)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var linkCache = cache.NewMemCache(cache.WithShards[*model.Link](16))
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +104,7 @@ func Link(ctx context.Context, account driver.Driver, path string, args model.Li
 | 
			
		|||
			return nil, errors.WithMessage(err, "failed to get file")
 | 
			
		||||
		}
 | 
			
		||||
		if file.IsDir() {
 | 
			
		||||
			return nil, errors.New("file is dir")
 | 
			
		||||
			return nil, errors.WithStack(errs.NotFile)
 | 
			
		||||
		}
 | 
			
		||||
		link, err := account.Link(ctx, file, args)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -123,7 +123,7 @@ func MakeDir(ctx context.Context, account driver.Driver, path string) error {
 | 
			
		|||
	// check if dir exists
 | 
			
		||||
	f, err := Get(ctx, account, path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if errs.IsErrObjectNotFound(err) {
 | 
			
		||||
		if errs.IsObjectNotFound(err) {
 | 
			
		||||
			parentPath, dirName := stdpath.Split(path)
 | 
			
		||||
			err = MakeDir(ctx, account, parentPath)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -183,7 +183,7 @@ func Remove(ctx context.Context, account driver.Driver, path string) error {
 | 
			
		|||
	obj, err := Get(ctx, account, path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// if object not found, it's ok
 | 
			
		||||
		if errs.IsErrObjectNotFound(err) {
 | 
			
		||||
		if errs.IsObjectNotFound(err) {
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
		return errors.WithMessage(err, "failed to get object")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +0,0 @@
 | 
			
		|||
package store
 | 
			
		||||
 | 
			
		||||
import "errors"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	ErrMetaNotFound = errors.New("meta not found")
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -2,6 +2,7 @@ package store
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/Xhofe/go-cache"
 | 
			
		||||
	"github.com/alist-org/alist/v3/internal/errs"
 | 
			
		||||
	"github.com/alist-org/alist/v3/internal/model"
 | 
			
		||||
	"github.com/alist-org/alist/v3/pkg/singleflight"
 | 
			
		||||
	"github.com/alist-org/alist/v3/pkg/utils"
 | 
			
		||||
| 
						 | 
				
			
			@ -25,7 +26,7 @@ func GetNearestMeta(path string) (*model.Meta, error) {
 | 
			
		|||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if path == "/" {
 | 
			
		||||
		return nil, errors.WithStack(ErrMetaNotFound)
 | 
			
		||||
		return nil, errors.WithStack(errs.MetaNotFound)
 | 
			
		||||
	}
 | 
			
		||||
	return GetNearestMeta(stdpath.Dir(path))
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue