func (mod *htmod) Handle(op ws.Op, r *ws.Res) { if op&(ws.Modify|ws.Delete) == 0 { return } if r.Flag&(ws.FlagIgnore|ws.FlagDir) != 0 { return } mod.docs.RLock() _, found := mod.docs.all[r.Id] mod.docs.RUnlock() if !found { return } mod.docs.Lock() defer mod.docs.Unlock() doc := mod.docs.all[r.Id] if doc == nil { return } doc.Lock() defer doc.Unlock() // delete doc if op&ws.Delete != 0 { mod.Hub.Del <- doc delete(mod.docs.all, doc.Id) msg, err := hub.Marshal("unsubscribe", apiRev{ Id: r.Id, User: DocGroup, }) if err != nil { fmt.Println(err) return } for _, cid := range doc.group { mod.Hub.SendMsg(msg, cid) } return } // update from filesystem data, err := ioutil.ReadFile(r.Path()) if err != nil { fmt.Println(err) return } rev := doc.Rev() ops := doc.diffops(data) if ops != nil { mod.handlerev("revise", apiRev{Id: r.Id, Rev: rev, Ops: ops}, doc) } }
func (s *Src) getorcreateres(r *ws.Res) *Pkg { pkg := s.getorcreate(r.Id, r.Path()) if pkg.Res == nil { pkg.Res = r pkg.Path = importPath(r) if s.lookup[pkg.Path] == nil { s.lookup[pkg.Path] = pkg } if r.Parent.Parent.Flag&FlagGo != 0 { pa := s.getorcreateres(r.Parent) if pa.Flag&Recursing != 0 { pkg.Flag |= Working | Watching | Recursing } pa.Pkgs = append(pa.Pkgs, pkg) } } return pkg }