fix(local): return ObjectNotFound
if can't find file
This commit is contained in:
parent
38db3508a5
commit
e9927806d4
@ -98,6 +98,9 @@ func (d *Local) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
|
|||||||
func (d *Local) Get(ctx context.Context, path string) (model.Obj, error) {
|
func (d *Local) Get(ctx context.Context, path string) (model.Obj, error) {
|
||||||
f, err := os.Stat(path)
|
f, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "cannot find the file") {
|
||||||
|
return nil, errors.WithStack(errs.ObjectNotFound)
|
||||||
|
}
|
||||||
return nil, errors.Wrapf(err, "error while stat %s", path)
|
return nil, errors.Wrapf(err, "error while stat %s", path)
|
||||||
}
|
}
|
||||||
file := model.Object{
|
file := model.Object{
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/alist-org/alist/v3/server/common"
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MkdirOrLinkReq struct {
|
type MkdirOrLinkReq struct {
|
||||||
@ -31,8 +32,10 @@ func FsMkdir(c *gin.Context) {
|
|||||||
if !user.CanWrite() {
|
if !user.CanWrite() {
|
||||||
meta, err := db.GetNearestMeta(req.Path)
|
meta, err := db.GetNearestMeta(req.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
|
||||||
return
|
common.ErrorResp(c, err, 500, true)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !canWrite(meta, req.Path) {
|
if !canWrite(meta, req.Path) {
|
||||||
common.ErrorResp(c, errs.PermissionDenied, 403)
|
common.ErrorResp(c, errs.PermissionDenied, 403)
|
||||||
@ -192,8 +195,10 @@ func FsPut(c *gin.Context) {
|
|||||||
if !user.CanWrite() {
|
if !user.CanWrite() {
|
||||||
meta, err := db.GetNearestMeta(path)
|
meta, err := db.GetNearestMeta(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
|
||||||
return
|
common.ErrorResp(c, err, 500, true)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !canWrite(meta, path) {
|
if !canWrite(meta, path) {
|
||||||
common.ErrorResp(c, errs.PermissionDenied, 403)
|
common.ErrorResp(c, errs.PermissionDenied, 403)
|
||||||
|
@ -114,7 +114,7 @@ func fs(g *gin.RouterGroup) {
|
|||||||
g.POST("/move", handles.FsMove)
|
g.POST("/move", handles.FsMove)
|
||||||
g.POST("/copy", handles.FsCopy)
|
g.POST("/copy", handles.FsCopy)
|
||||||
g.POST("/remove", handles.FsRemove)
|
g.POST("/remove", handles.FsRemove)
|
||||||
g.POST("/put", handles.FsPut)
|
g.PUT("/put", handles.FsPut)
|
||||||
g.POST("/link", middlewares.AuthAdmin, handles.Link)
|
g.POST("/link", middlewares.AuthAdmin, handles.Link)
|
||||||
g.POST("/add_aria2", handles.AddAria2)
|
g.POST("/add_aria2", handles.AddAria2)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user