mirror of
https://github.com/chrislusf/seaweedfs
synced 2024-06-30 22:31:06 +02:00
Fix: http rename move dir to subdir (#4432)
Co-authored-by: wang wusong <wangwusong@virtaitech.com>
This commit is contained in:
parent
d75a7b7f62
commit
4867aa03ab
|
@ -2,16 +2,23 @@ package filer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *Filer) CanRename(source, target util.FullPath) error {
|
func (f *Filer) CanRename(source, target util.FullPath, oldName string) error {
|
||||||
|
sourcePath := source.Child(oldName)
|
||||||
|
if strings.HasPrefix(string(target), string(sourcePath)) {
|
||||||
|
return fmt.Errorf("mv: can not move directory to a subdirectory of itself")
|
||||||
|
}
|
||||||
|
|
||||||
sourceBucket := f.DetectBucket(source)
|
sourceBucket := f.DetectBucket(source)
|
||||||
targetBucket := f.DetectBucket(target)
|
targetBucket := f.DetectBucket(target)
|
||||||
if sourceBucket != targetBucket {
|
if sourceBucket != targetBucket {
|
||||||
return fmt.Errorf("can not move across collection %s => %s", sourceBucket, targetBucket)
|
return fmt.Errorf("can not move across collection %s => %s", sourceBucket, targetBucket)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.Atom
|
||||||
oldParent := util.FullPath(filepath.ToSlash(req.OldDirectory))
|
oldParent := util.FullPath(filepath.ToSlash(req.OldDirectory))
|
||||||
newParent := util.FullPath(filepath.ToSlash(req.NewDirectory))
|
newParent := util.FullPath(filepath.ToSlash(req.NewDirectory))
|
||||||
|
|
||||||
if err := fs.filer.CanRename(oldParent, newParent); err != nil {
|
if err := fs.filer.CanRename(oldParent, newParent, req.OldName); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func (fs *FilerServer) StreamRenameEntry(req *filer_pb.StreamRenameEntryRequest,
|
||||||
oldParent := util.FullPath(filepath.ToSlash(req.OldDirectory))
|
oldParent := util.FullPath(filepath.ToSlash(req.OldDirectory))
|
||||||
newParent := util.FullPath(filepath.ToSlash(req.NewDirectory))
|
newParent := util.FullPath(filepath.ToSlash(req.NewDirectory))
|
||||||
|
|
||||||
if err := fs.filer.CanRename(oldParent, newParent); err != nil {
|
if err := fs.filer.CanRename(oldParent, newParent, req.OldName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue