func HandleWrite(ctx syncer.Context, l uri.Uri, r uri.Uri) error { if l.ModTime().Sub(r.ModTime()) < 0 { return ctx.Finish() } var ( reader io.ReadCloser writer io.WriteCloser err error ) for { reader, err = l.OpenRead() if err == nil { break } time.Sleep(time.Second * 20) } for { writer, err = r.OpenWrite() if err == nil { break } time.Sleep(time.Minute * 10) } defer reader.Close() defer writer.Close() _, err = io.Copy(writer, reader) if err != nil { ctx.EmitLog(syncer.TypeError, err) } ctx.EmitLog(syncer.TypeInfo, "write to ", r.Uri()) return err }
func (v *localVisitor) Visit(u uri.Uri) error { // fmt.Println("visit", u.Uri()) if !u.IsDir() { v.s.msg <- Message{u.Abs(), v.p, fsnotify.Write} return nil } if filepath.Base(u.Abs()) == ".git" { return filepath.SkipDir } v.p.watcher.Add(u.Abs()) v.s.msg <- Message{u.Abs(), v.p, fsnotify.Create} return nil }
func HandleAddNewWatch(ctx syncer.Context, l uri.Uri, r uri.Uri) error { if filepath.Base(l.Abs()) == ".git" { return ctx.Finish() } if !l.IsDir() { return nil } err := ctx.AddWatch(l) if err != nil { ctx.EmitLog(syncer.TypeError, err) } return nil }
func HandleCreate(ctx syncer.Context, l uri.Uri, r uri.Uri) error { if l.ModTime().Sub(r.ModTime()) < 0 { return ctx.Finish() } var err error for { err = r.Create(l.IsDir(), l.Mode()) if err == nil { break } time.Sleep(time.Minute * 1) } ctx.EmitLog(syncer.TypeInfo, "create ", r.Uri()) return nil }
func (ctx Context) RemoveWatch(u uri.Uri) error { return ctx.p.watcher.Remove(u.Abs()) }
func (p *Pair) AddWatch(u uri.Uri) error { if p.watcher == nil { return errors.New("nil watcher") } return p.watcher.Add(u.Abs()) }