added base path filter

This commit is contained in:
ston1th 2019-05-03 10:44:17 +02:00
commit ec5a376733
15 changed files with 104 additions and 44 deletions

View file

@ -54,6 +54,10 @@ func (fs *Filesystem) NewFile(r io.Reader, path, orig, name string) (newfile str
name = orig
}
newfile = filepath.Join(path, name)
err = checkPath(newfile)
if err != nil {
return
}
f, err := os.OpenFile(filepath.Join(fs.Base, newfile), os.O_RDWR|os.O_CREATE, FileMode)
if err != nil {
return
@ -64,7 +68,12 @@ func (fs *Filesystem) NewFile(r io.Reader, path, orig, name string) (newfile str
}
func (fs *Filesystem) Mkdir(path, name string) error {
return os.Mkdir(filepath.Join(fs.Base, Clean(path), Clean(name)), DirMode)
dirpath := filepath.Join(Clean(path), Clean(name))
err := checkPath(dirpath)
if err != nil {
return err
}
return os.Mkdir(filepath.Join(fs.Base, dirpath), DirMode)
}
func (fs *Filesystem) Move(path, dest, name string) (string, error) {
@ -75,7 +84,11 @@ func (fs *Filesystem) Move(path, dest, name string) (string, error) {
if fullpath == fs.Base {
return "", errors.New("the root path can not be moved")
}
newfile := Clean(filepath.Join(dest, name))
newfile := filepath.Join(Clean(dest), Clean(name))
err := checkPath(newfile)
if err != nil {
return "", err
}
return newfile, os.Rename(fullpath, filepath.Join(fs.Base, newfile))
}