mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-07 04:00:17 -06:00
[server][webdav] use errors.Is instead os.IsNotExist
This commit is contained in:
@@ -6,6 +6,7 @@ package webdav
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -34,7 +35,7 @@ type FileSystem interface {
|
||||
func moveFiles(ctx context.Context, fs FileSystem, src, dst string, overwrite bool) (status int, err error) {
|
||||
created := false
|
||||
if _, err := fs.Stat(ctx, dst); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return http.StatusForbidden, err
|
||||
}
|
||||
created = true
|
||||
@@ -72,7 +73,7 @@ func copyFiles(ctx context.Context, fs FileSystem, src, dst string, overwrite bo
|
||||
|
||||
srcStat, err := fs.Stat(ctx, src)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return http.StatusNotFound, err
|
||||
}
|
||||
return http.StatusInternalServerError, err
|
||||
@@ -80,7 +81,7 @@ func copyFiles(ctx context.Context, fs FileSystem, src, dst string, overwrite bo
|
||||
|
||||
created := false
|
||||
if _, err := fs.Stat(ctx, dst); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
created = true
|
||||
} else {
|
||||
return http.StatusForbidden, err
|
||||
@@ -89,7 +90,7 @@ func copyFiles(ctx context.Context, fs FileSystem, src, dst string, overwrite bo
|
||||
if !overwrite {
|
||||
return http.StatusPreconditionFailed, os.ErrExist
|
||||
}
|
||||
if err := fs.RemoveAll(ctx, dst); err != nil && !os.IsNotExist(err) {
|
||||
if err := fs.RemoveAll(ctx, dst); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return http.StatusForbidden, err
|
||||
}
|
||||
}
|
||||
@@ -118,7 +119,7 @@ func copyFiles(ctx context.Context, fs FileSystem, src, dst string, overwrite bo
|
||||
} else {
|
||||
srcFile, err := fs.OpenRead(srcStat, 0, -1)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return http.StatusNotFound, err
|
||||
}
|
||||
return http.StatusInternalServerError, err
|
||||
@@ -126,7 +127,7 @@ func copyFiles(ctx context.Context, fs FileSystem, src, dst string, overwrite bo
|
||||
defer srcFile.Close()
|
||||
dstFile, err := fs.OpenWrite(ctx, dst)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return http.StatusConflict, err
|
||||
}
|
||||
return http.StatusForbidden, err
|
||||
|
||||
@@ -234,7 +234,7 @@ func (h *Handler) handleDelete(_ http.ResponseWriter, r *http.Request) (status i
|
||||
// returns nil (no error)." WebDAV semantics are that it should return a
|
||||
// "404 Not Found". We therefore have to Stat before we RemoveAll.
|
||||
if _, err := h.FileSystem.Stat(ctx, reqPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return http.StatusNotFound, err
|
||||
}
|
||||
return http.StatusMethodNotAllowed, err
|
||||
@@ -297,7 +297,7 @@ func (h *Handler) handleMkcol(_ http.ResponseWriter, r *http.Request) (status in
|
||||
return http.StatusUnsupportedMediaType, nil
|
||||
}
|
||||
if err := h.FileSystem.Mkdir(ctx, reqPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrExist) {
|
||||
return http.StatusConflict, err
|
||||
}
|
||||
return http.StatusMethodNotAllowed, err
|
||||
@@ -505,7 +505,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status
|
||||
ctx := r.Context()
|
||||
fi, err := h.FileSystem.Stat(ctx, reqPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return http.StatusNotFound, err
|
||||
}
|
||||
return http.StatusMethodNotAllowed, err
|
||||
@@ -580,7 +580,7 @@ func (h *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) (statu
|
||||
ctx := r.Context()
|
||||
|
||||
if _, err := h.FileSystem.Stat(ctx, reqPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return http.StatusNotFound, err
|
||||
}
|
||||
return http.StatusMethodNotAllowed, err
|
||||
|
||||
Reference in New Issue
Block a user