mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-24 19:49:56 +08:00
chore: check against errors of io/fs
instead of os
(#6011)
* chore: replace `os.ErrNotExist` with `fs.ErrNotExist` * check against permission error from `io/fs` package
This commit is contained in:

committed by
GitHub

parent
b568a10dd4
commit
787f6b257f
@ -19,6 +19,7 @@ import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
@ -92,9 +93,9 @@ func (fsrv *FileServer) serveBrowse(root, dirPath string, w http.ResponseWriter,
|
||||
// TODO: not entirely sure if path.Clean() is necessary here but seems like a safe plan (i.e. /%2e%2e%2f) - someone could verify this
|
||||
listing, err := fsrv.loadDirectoryContents(r.Context(), dir.(fs.ReadDirFile), root, path.Clean(r.URL.EscapedPath()), repl)
|
||||
switch {
|
||||
case os.IsPermission(err):
|
||||
case errors.Is(err, fs.ErrPermission):
|
||||
return caddyhttp.Error(http.StatusForbidden, err)
|
||||
case os.IsNotExist(err):
|
||||
case errors.Is(err, fs.ErrNotExist):
|
||||
return fsrv.notFound(w, r, next)
|
||||
case err != nil:
|
||||
return caddyhttp.Error(http.StatusInternalServerError, err)
|
||||
|
Reference in New Issue
Block a user