added base path filter
This commit is contained in:
parent
98b53d3a33
commit
ec5a376733
15 changed files with 104 additions and 44 deletions
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue