You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

clone.go 809 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package ops
  2. import (
  3. "io"
  4. "sync"
  5. myio "gitlink.org.cn/cloudream/common/utils/io"
  6. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch"
  7. )
  8. type Clone struct {
  9. InputID ioswitch.StreamID `json:"inputID"`
  10. OutputIDs []ioswitch.StreamID `json:"outputIDs"`
  11. }
  12. func (o *Clone) Execute(sw *ioswitch.Switch, planID ioswitch.PlanID) error {
  13. strs, err := sw.WaitStreams(planID, o.InputID)
  14. if err != nil {
  15. return err
  16. }
  17. defer strs[0].Stream.Close()
  18. wg := sync.WaitGroup{}
  19. cloned := myio.Clone(strs[0].Stream, len(o.OutputIDs))
  20. for i, s := range cloned {
  21. wg.Add(1)
  22. sw.StreamReady(planID,
  23. ioswitch.NewStream(o.OutputIDs[i],
  24. myio.AfterReadClosedOnce(s, func(closer io.ReadCloser) {
  25. wg.Done()
  26. }),
  27. ),
  28. )
  29. }
  30. wg.Wait()
  31. return nil
  32. }
  33. func init() {
  34. OpUnion.AddT((*Clone)(nil))
  35. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。