mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-01 00:23:48 +03:00
staticfiles: remove mapFSRootOpenErr because Go stdlib has fixed the relevant issue (#1919)
This commit is contained in:
parent
0548b97701
commit
79072828a5
1 changed files with 0 additions and 35 deletions
|
@ -66,9 +66,6 @@ func (fs FileServer) serveFile(w http.ResponseWriter, r *http.Request) (int, err
|
||||||
// open the requested file
|
// open the requested file
|
||||||
f, err := fs.Root.Open(reqPath)
|
f, err := fs.Root.Open(reqPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: remove when http.Dir handles this (Go 1.9?)
|
|
||||||
// Go issue #18984
|
|
||||||
err = mapFSRootOpenErr(err)
|
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return http.StatusNotFound, nil
|
return http.StatusNotFound, nil
|
||||||
} else if os.IsPermission(err) {
|
} else if os.IsPermission(err) {
|
||||||
|
@ -280,35 +277,3 @@ var staticEncodingPriority = []string{
|
||||||
"br",
|
"br",
|
||||||
"gzip",
|
"gzip",
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapFSRootOpenErr maps the provided non-nil error
|
|
||||||
// to a possibly better non-nil error. In particular, it turns OS-specific errors
|
|
||||||
// about opening files in non-directories into os.ErrNotExist.
|
|
||||||
//
|
|
||||||
// TODO: remove when http.Dir handles this (slated for Go 1.9)
|
|
||||||
// Go issue #18984
|
|
||||||
func mapFSRootOpenErr(originalErr error) error {
|
|
||||||
if os.IsNotExist(originalErr) || os.IsPermission(originalErr) {
|
|
||||||
return originalErr
|
|
||||||
}
|
|
||||||
|
|
||||||
perr, ok := originalErr.(*os.PathError)
|
|
||||||
if !ok {
|
|
||||||
return originalErr
|
|
||||||
}
|
|
||||||
name := perr.Path
|
|
||||||
parts := strings.Split(name, string(filepath.Separator))
|
|
||||||
for i := range parts {
|
|
||||||
if parts[i] == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fi, err := os.Stat(strings.Join(parts[:i+1], string(filepath.Separator)))
|
|
||||||
if err != nil {
|
|
||||||
return originalErr
|
|
||||||
}
|
|
||||||
if !fi.IsDir() {
|
|
||||||
return os.ErrNotExist
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return originalErr
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue