fix: Correct backend lint issues

pull/3756/head
Laurynas Gadliauskas 2024-11-11 16:06:34 +02:00
parent ddb21c0f5e
commit 944631b6dc
3 changed files with 10 additions and 6 deletions

View File

@ -2,7 +2,7 @@ linters-settings:
dupl: dupl:
threshold: 100 threshold: 100
exhaustive: exhaustive:
default-signifies-exhaustive: false default-signifies-exhaustive: true
funlen: funlen:
lines: 100 lines: 100
statements: 50 statements: 50

View File

@ -1,13 +1,14 @@
package http package http
import ( import (
"errors"
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
"github.com/tomasen/realip" "github.com/tomasen/realip"
"github.com/filebrowser/filebrowser/v2/errors" fbErrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/filebrowser/filebrowser/v2/rules"
"github.com/filebrowser/filebrowser/v2/runner" "github.com/filebrowser/filebrowser/v2/runner"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/settings"
@ -74,7 +75,8 @@ func handle(fn handleFunc, prefix string, store *storage.Storage, server *settin
if status != 0 { if status != 0 {
txt := strconv.Itoa(status) + " " + http.StatusText(status) txt := strconv.Itoa(status) + " " + http.StatusText(status)
if httpErr, ok := err.(*errors.HTTPError); ok { var httpErr *fbErrors.HTTPError
if errors.As(err, &httpErr) {
txt += " [" + httpErr.Type + "]" txt += " [" + httpErr.Type + "]"
} }
http.Error(w, txt, status) http.Error(w, txt, status)

View File

@ -670,6 +670,8 @@ func chmodActionHandler(r *http.Request, d *data) error {
return fbErrors.ErrInvalidRequestParams return fbErrors.ErrInvalidRequestParams
} }
permMode := uint32(mode)
info, err := d.user.Fs.Stat(target) info, err := d.user.Fs.Stat(target)
if err != nil { if err != nil {
return err return err
@ -688,7 +690,7 @@ func chmodActionHandler(r *http.Request, d *data) error {
return !i.IsDir() return !i.IsDir()
} }
default: default:
recFilter = func(i os.FileInfo) bool { recFilter = func(_ os.FileInfo) bool {
return true return true
} }
} }
@ -696,12 +698,12 @@ func chmodActionHandler(r *http.Request, d *data) error {
return afero.Walk(d.user.Fs, target, func(name string, info os.FileInfo, err error) error { return afero.Walk(d.user.Fs, target, func(name string, info os.FileInfo, err error) error {
if err == nil { if err == nil {
if recFilter(info) { if recFilter(info) {
err = d.user.Fs.Chmod(name, os.FileMode(mode)) err = d.user.Fs.Chmod(name, os.FileMode(permMode))
} }
} }
return err return err
}) })
} }
return d.user.Fs.Chmod(target, os.FileMode(mode)) return d.user.Fs.Chmod(target, os.FileMode(permMode))
} }