aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/filer_rename.go
blob: b6f0cf6deb97b53617990287cc681a868c16591b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}