fix: resource rename action invalid path
parent
d562d1a60d
commit
1ce3068a99
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ var resourcePostPutHandler = withUser(func(w http.ResponseWriter, r *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
err := d.RunHook(func() error {
|
err := d.RunHook(func() error {
|
||||||
dir, _ := filepath.Split(r.URL.Path)
|
dir, _ := path.Split(r.URL.Path)
|
||||||
err := d.user.Fs.MkdirAll(dir, 0775)
|
err := d.user.Fs.MkdirAll(dir, 0775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -196,7 +197,8 @@ var resourcePatchHandler = withUser(func(w http.ResponseWriter, r *http.Request,
|
||||||
if !d.user.Perm.Rename {
|
if !d.user.Perm.Rename {
|
||||||
return errors.ErrPermissionDenied
|
return errors.ErrPermissionDenied
|
||||||
}
|
}
|
||||||
dst = filepath.Clean("/" + dst)
|
src = path.Clean("/" + src)
|
||||||
|
dst = path.Clean("/" + dst)
|
||||||
|
|
||||||
return d.user.Fs.Rename(src, dst)
|
return d.user.Fs.Rename(src, dst)
|
||||||
default:
|
default:
|
||||||
|
@ -221,20 +223,20 @@ func checkParent(src, dst string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addVersionSuffix(path string, fs afero.Fs) string {
|
func addVersionSuffix(source string, fs afero.Fs) string {
|
||||||
counter := 1
|
counter := 1
|
||||||
dir, name := filepath.Split(path)
|
dir, name := path.Split(source)
|
||||||
ext := filepath.Ext(name)
|
ext := filepath.Ext(name)
|
||||||
base := strings.TrimSuffix(name, ext)
|
base := strings.TrimSuffix(name, ext)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if _, err := fs.Stat(path); err != nil {
|
if _, err := fs.Stat(source); err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
renamed := fmt.Sprintf("%s(%d)%s", base, counter, ext)
|
renamed := fmt.Sprintf("%s(%d)%s", base, counter, ext)
|
||||||
path = filepath.ToSlash(dir) + renamed
|
source = path.Join(dir, renamed)
|
||||||
counter++
|
counter++
|
||||||
}
|
}
|
||||||
|
|
||||||
return path
|
return source
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue