mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-21 09:57:24 +08:00
check cross device rename error
This commit is contained in:
30
weed/filer/filer_rename.go
Normal file
30
weed/filer/filer_rename.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package filer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (f *Filer) CanRename(source, target util.FullPath) error {
|
||||
sourceBucket := f.DetectBucket(source)
|
||||
targetBucket := f.DetectBucket(target)
|
||||
if sourceBucket != targetBucket {
|
||||
return fmt.Errorf("can not move across collection %s => %s", sourceBucket, targetBucket)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Filer) DetectBucket(source util.FullPath) (bucket string) {
|
||||
if strings.HasPrefix(string(source), f.DirBucketsPath+"/") {
|
||||
bucketAndObjectKey := string(source)[len(f.DirBucketsPath)+1:]
|
||||
t := strings.Index(bucketAndObjectKey, "/")
|
||||
if t < 0 {
|
||||
bucket = bucketAndObjectKey
|
||||
}
|
||||
if t > 0 {
|
||||
bucket = bucketAndObjectKey[:t]
|
||||
}
|
||||
}
|
||||
return bucket
|
||||
}
|
@@ -42,7 +42,7 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirector
|
||||
_, err := client.AtomicRenameEntry(ctx, request)
|
||||
if err != nil {
|
||||
glog.Errorf("dir AtomicRenameEntry %s => %s : %v", oldPath, newPath, err)
|
||||
return fuse.EIO
|
||||
return fuse.EXDEV
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -15,13 +15,18 @@ func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.Atom
|
||||
|
||||
glog.V(1).Infof("AtomicRenameEntry %v", req)
|
||||
|
||||
oldParent := util.FullPath(filepath.ToSlash(req.OldDirectory))
|
||||
newParent := util.FullPath(filepath.ToSlash(req.NewDirectory))
|
||||
|
||||
if err := fs.filer.CanRename(oldParent, newParent); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, err := fs.filer.BeginTransaction(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
oldParent := util.FullPath(filepath.ToSlash(req.OldDirectory))
|
||||
|
||||
oldEntry, err := fs.filer.FindEntry(ctx, oldParent.Child(req.OldName))
|
||||
if err != nil {
|
||||
fs.filer.RollbackTransaction(ctx)
|
||||
@@ -29,7 +34,7 @@ func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.Atom
|
||||
}
|
||||
|
||||
var events MoveEvents
|
||||
moveErr := fs.moveEntry(ctx, oldParent, oldEntry, util.FullPath(filepath.ToSlash(req.NewDirectory)), req.NewName, &events)
|
||||
moveErr := fs.moveEntry(ctx, oldParent, oldEntry, newParent, req.NewName, &events)
|
||||
if moveErr != nil {
|
||||
fs.filer.RollbackTransaction(ctx)
|
||||
return nil, fmt.Errorf("%s/%s move error: %v", req.OldDirectory, req.OldName, moveErr)
|
||||
|
@@ -111,14 +111,7 @@ func (fs *FilerServer) detectStorageOption(requestURI, qCollection, qReplication
|
||||
// required by buckets folder
|
||||
bucketDefaultReplication, fsync := "", false
|
||||
if strings.HasPrefix(requestURI, fs.filer.DirBucketsPath+"/") {
|
||||
bucketAndObjectKey := requestURI[len(fs.filer.DirBucketsPath)+1:]
|
||||
t := strings.Index(bucketAndObjectKey, "/")
|
||||
if t < 0 {
|
||||
collection = bucketAndObjectKey
|
||||
}
|
||||
if t > 0 {
|
||||
collection = bucketAndObjectKey[:t]
|
||||
}
|
||||
collection = fs.filer.DetectBucket(util.FullPath(requestURI))
|
||||
bucketDefaultReplication, fsync = fs.filer.ReadBucketOption(collection)
|
||||
}
|
||||
if replication == "" {
|
||||
|
Reference in New Issue
Block a user