webdav: remove path from LocalFileSystem path errors

We don't want to show local paths in error messages.

`os.Is*` calls were replaced with `errors.Is` to also match the new
wrapped error.
This commit is contained in:
krystiancha
2025-03-05 08:48:59 +01:00
committed by GitHub
parent 002c347f47
commit b689d5daff

View File

@@ -2,8 +2,10 @@ package webdav
import (
"context"
"errors"
"fmt"
"io"
"io/fs"
"mime"
"net/http"
"os"
@@ -64,11 +66,17 @@ func fileInfoFromOS(p string, fi os.FileInfo) *FileInfo {
}
func errFromOS(err error) error {
if os.IsNotExist(err) {
// Remove path from path errors so it's not returned to the user
var perr *fs.PathError
if errors.As(err, &perr) {
err = fmt.Errorf("%s: %w", perr.Op, perr.Err)
}
if errors.Is(err, fs.ErrNotExist) {
return NewHTTPError(http.StatusNotFound, err)
} else if os.IsPermission(err) {
} else if errors.Is(err, fs.ErrPermission) {
return NewHTTPError(http.StatusForbidden, err)
} else if os.IsTimeout(err) {
} else if errors.Is(err, os.ErrDeadlineExceeded) {
return NewHTTPError(http.StatusServiceUnavailable, err)
} else {
return err