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

  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. }