filer_rename.go 739 B

123456789101112131415161718192021222324252627282930
  1. package filer
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/util"
  5. "strings"
  6. )
  7. func (f *Filer) CanRename(source, target util.FullPath) error {
  8. sourceBucket := f.DetectBucket(source)
  9. targetBucket := f.DetectBucket(target)
  10. if sourceBucket != targetBucket {
  11. return fmt.Errorf("can not move across collection %s => %s", sourceBucket, targetBucket)
  12. }
  13. return nil
  14. }
  15. func (f *Filer) DetectBucket(source util.FullPath) (bucket string) {
  16. if strings.HasPrefix(string(source), f.DirBucketsPath+"/") {
  17. bucketAndObjectKey := string(source)[len(f.DirBucketsPath)+1:]
  18. t := strings.Index(bucketAndObjectKey, "/")
  19. if t < 0 {
  20. bucket = bucketAndObjectKey
  21. }
  22. if t > 0 {
  23. bucket = bucketAndObjectKey[:t]
  24. }
  25. }
  26. return bucket
  27. }