diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-12-10 23:50:32 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-12-10 23:50:32 -0800 |
| commit | 3fedfec1e728e84120caa636b7d0d3da0fcffbc4 (patch) | |
| tree | aa9e75f2f206f79a32c887c11f945086ce42644d /weed/filer/filer_rename.go | |
| parent | c2f18a10cbca811705c3086f35811dc052c28853 (diff) | |
| download | seaweedfs-3fedfec1e728e84120caa636b7d0d3da0fcffbc4.tar.xz seaweedfs-3fedfec1e728e84120caa636b7d0d3da0fcffbc4.zip | |
check cross device rename error
Diffstat (limited to 'weed/filer/filer_rename.go')
| -rw-r--r-- | weed/filer/filer_rename.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/weed/filer/filer_rename.go b/weed/filer/filer_rename.go new file mode 100644 index 000000000..b6f0cf6de --- /dev/null +++ b/weed/filer/filer_rename.go @@ -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 +} |
