You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
739 B
30 lines
739 B
package filer
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/seaweedfs/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
|
|
}
|