Пример #1
0
func (s *Syncer) AddPair(left, right string, config *PairConfig) error {

	lUri, err := uri.Parse(left)
	if err != nil {
		return err
	}
	rUri, err := uri.Parse(right)
	if err != nil {
		return err
	}
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		return err
	}

	p := &Pair{
		Left:     lUri,
		Right:    rUri,
		watcher:  watcher,
		progress: make(chan int64),
		handlers: make(map[fsnotify.Op][]OpHandler),
		syncer:   s,
		Config:   config,
	}
	s.Pairs = append(s.Pairs, p)
	go func(pair *Pair) {
		s.addPair <- pair
		fmt.Println("add pair", pair.Left.Uri())
	}(p)
	return nil
}
Пример #2
0
func prepair(name string, p *Pair) (l uri.Uri, r uri.Uri, err error) {
	name = strings.Replace(name, "\\", "/", -1)
	lName := p.Left.Scheme() + "://" + name
	l, err = uri.Parse(lName)
	if err != nil {
		return nil, nil, err
	}

	lTmp := p.Left.Uri()
	rTmp := p.Right.Uri()
	lTmplen := len(lTmp)
	rTmplen := len(rTmp)
	if lTmp[lTmplen-1] == '/' {
		lTmp = lTmp[0 : lTmplen-1]
	}
	if rTmp[rTmplen-1] == '/' {
		rTmp = rTmp[0 : rTmplen-1]
	}
	Uris := strings.Replace(l.Uri(), lTmp, rTmp, -1)
	r, err = uri.Parse(Uris)
	return
}