fixed some path issues
This commit is contained in:
parent
ffeeae5702
commit
38c2a72fe0
5 changed files with 22 additions and 28 deletions
|
|
@ -2,11 +2,9 @@ package fs
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/core"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Mode int
|
||||
|
|
@ -18,8 +16,7 @@ const (
|
|||
)
|
||||
|
||||
func (fs *Filesystem) GetFile(path string) (f *os.File, fi os.FileInfo, err error) {
|
||||
path = strings.TrimPrefix(Clean(path), core.RawPrefix)
|
||||
p := filepath.Join(fs.Base, path)
|
||||
p := filepath.Join(fs.Base, Clean(path))
|
||||
f, err = os.Open(p)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -35,8 +32,7 @@ func (fs *Filesystem) GetFile(path string) (f *os.File, fi os.FileInfo, err erro
|
|||
}
|
||||
|
||||
func (fs *Filesystem) Mode(path string) (mode Mode, err error) {
|
||||
path = Clean(path)
|
||||
p := filepath.Join(fs.Base, path)
|
||||
p := filepath.Join(fs.Base, Clean(path))
|
||||
fi, err := os.Stat(p)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -52,10 +48,8 @@ func (fs *Filesystem) Mode(path string) (mode Mode, err error) {
|
|||
|
||||
func (fs *Filesystem) NewFile(r io.Reader, path, orig, name string) (newfile string, err error) {
|
||||
path = Clean(path)
|
||||
orig = Clean(orig)
|
||||
_, orig = filepath.Split(orig)
|
||||
name = Clean(name)
|
||||
_, name = filepath.Split(name)
|
||||
orig = File(orig)
|
||||
name = File(name)
|
||||
if name == "" {
|
||||
name = orig
|
||||
}
|
||||
|
|
@ -70,17 +64,14 @@ func (fs *Filesystem) NewFile(r io.Reader, path, orig, name string) (newfile str
|
|||
}
|
||||
|
||||
func (fs *Filesystem) Mkdir(path, name string) error {
|
||||
path = Clean(path)
|
||||
name = Clean(name)
|
||||
return os.Mkdir(filepath.Join(fs.Base, path, name), DirMode)
|
||||
return os.Mkdir(filepath.Join(fs.Base, Clean(path), Clean(name)), DirMode)
|
||||
}
|
||||
|
||||
func (fs *Filesystem) Move(path, dest, name string) (string, error) {
|
||||
path = Clean(path)
|
||||
if name == "" {
|
||||
_, name = filepath.Split(path)
|
||||
name = File(path)
|
||||
}
|
||||
fullpath := filepath.Join(fs.Base, path)
|
||||
fullpath := filepath.Join(fs.Base, Clean(path))
|
||||
if fullpath == fs.Base {
|
||||
return "", errors.New("the root path can not be moved")
|
||||
}
|
||||
|
|
@ -100,11 +91,11 @@ func (fs *Filesystem) Delete(path string) (removed []string, err error) {
|
|||
}
|
||||
m := fi.Mode()
|
||||
if m.IsDir() {
|
||||
err = os.RemoveAll(fullpath)
|
||||
removed = fs.RecursiveFiles(path)
|
||||
err = os.RemoveAll(fullpath)
|
||||
} else if m.IsRegular() {
|
||||
err = os.Remove(fullpath)
|
||||
removed = []string{path}
|
||||
err = os.Remove(fullpath)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue