some bug fixes
This commit is contained in:
parent
0e49d60994
commit
0e914c629e
16 changed files with 179 additions and 52 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Mode int
|
||||
|
|
@ -78,20 +79,40 @@ func (fs *Filesystem) Mkdir(path, name string) error {
|
|||
return os.Mkdir(filepath.Join(fs.Base, dirpath), DirMode)
|
||||
}
|
||||
|
||||
func (fs *Filesystem) Move(path, dest, name string) (string, error) {
|
||||
type Moved struct {
|
||||
Old string
|
||||
New string
|
||||
}
|
||||
|
||||
func (fs *Filesystem) Move(path, dest, name string) (moved []Moved, newfile string, err error) {
|
||||
if name == "" {
|
||||
name = File(path)
|
||||
}
|
||||
fullpath := filepath.Join(fs.Base, Clean(path))
|
||||
path = Clean(path)
|
||||
fullpath := filepath.Join(fs.Base, path)
|
||||
if fullpath == fs.Base {
|
||||
return "", errors.New("the root path can not be moved")
|
||||
err = errors.New("the root path can not be moved")
|
||||
return
|
||||
}
|
||||
newfile := filepath.Join(Clean(dest), Clean(name))
|
||||
err := checkPath(newfile)
|
||||
newfile = filepath.Join(Clean(dest), Clean(name))
|
||||
err = checkPath(newfile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return
|
||||
}
|
||||
return newfile, os.Rename(fullpath, filepath.Join(fs.Base, newfile))
|
||||
fi, err := os.Stat(fullpath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
m := fi.Mode()
|
||||
if m.IsDir() {
|
||||
for _, f := range fs.RecursiveFiles(path) {
|
||||
moved = append(moved, Moved{f, strings.Replace(f, path, newfile, 1)})
|
||||
}
|
||||
} else if m.IsRegular() {
|
||||
moved = append(moved, Moved{path, newfile})
|
||||
}
|
||||
err = os.Rename(fullpath, filepath.Join(fs.Base, newfile))
|
||||
return
|
||||
}
|
||||
|
||||
func (fs *Filesystem) Delete(path string) (removed []string, err error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue