Skip to content

Commit

Permalink
fix(local): return ObjectNotFound if can't find file
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 19, 2022
1 parent 38db350 commit e992780
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions drivers/local/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
f, err := os.Stat(path)
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)
}
file := model.Object{
Expand Down
13 changes: 9 additions & 4 deletions server/handles/fsmanage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)

type MkdirOrLinkReq struct {
Expand All @@ -31,8 +32,10 @@ func FsMkdir(c *gin.Context) {
if !user.CanWrite() {
meta, err := db.GetNearestMeta(req.Path)
if err != nil {
common.ErrorResp(c, err, 500)
return
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
common.ErrorResp(c, err, 500, true)
return
}
}
if !canWrite(meta, req.Path) {
common.ErrorResp(c, errs.PermissionDenied, 403)
Expand Down Expand Up @@ -192,8 +195,10 @@ func FsPut(c *gin.Context) {
if !user.CanWrite() {
meta, err := db.GetNearestMeta(path)
if err != nil {
common.ErrorResp(c, err, 500)
return
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
common.ErrorResp(c, err, 500, true)
return
}
}
if !canWrite(meta, path) {
common.ErrorResp(c, errs.PermissionDenied, 403)
Expand Down
2 changes: 1 addition & 1 deletion server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func fs(g *gin.RouterGroup) {
g.POST("/move", handles.FsMove)
g.POST("/copy", handles.FsCopy)
g.POST("/remove", handles.FsRemove)
g.POST("/put", handles.FsPut)
g.PUT("/put", handles.FsPut)
g.POST("/link", middlewares.AuthAdmin, handles.Link)
g.POST("/add_aria2", handles.AddAria2)
}
Expand Down

0 comments on commit e992780

Please sign in to comment.