Exemplo n.º 1
0
func (mod *htmod) stat(path string) (hub.Msg, error) {
	res := apiRes{ws.NewId(path), path, false}
	if r := mod.ws.Res(res.Id); r != nil {
		r.Lock()
		defer r.Unlock()
		res.Name, res.IsDir = r.Name, r.Flag&ws.FlagDir != 0
		if r.Dir != nil {
			cs := make([]apiRes, 0, len(r.Children))
			for _, c := range r.Children {
				if c.Flag&ws.FlagIgnore == 0 {
					cs = append(cs, apiRes{
						c.Id,
						c.Name,
						c.Flag&ws.FlagDir != 0,
					})
				}
			}
			return hub.Marshal("stat", struct {
				apiRes
				Path     string
				Children []apiRes
			}{res, path, cs})
		}
		return hub.Marshal("stat", struct {
			apiRes
			Path string
		}{res, path})
	}
	return hub.Marshal("stat.err", struct {
		apiRes
		Path  string
		Error string
	}{res, path, "not found"})
}
Exemplo n.º 2
0
Arquivo: gosrc.go Projeto: napsy/lab
func New() *Src {
	s := &Src{
		pkgs:   make(map[ws.Id]*Pkg),
		lookup: make(map[string]*Pkg),
		queue:  ws.NewThrottle(time.Second),
		rmchan: make(chan *ws.Res),
	}
	p := Pkg{Id: ws.NewId("C"), Path: "C"}
	p.Name = "C"
	p.Src.Info = &Info{}
	s.lookup["C"] = &p
	return s
}
Exemplo n.º 3
0
Arquivo: gosrc.go Projeto: napsy/lab
func (s *Src) Init() {
	var ids []ws.Id
	for _, d := range build.Default.SrcDirs() {
		ids = append(ids, ws.NewId(d))
	}
	s.srcids = ids
	for _, p := range filepath.SplitList(*workpaths) {
		err := s.WorkOn(p)
		if err != nil {
			fmt.Println(err)
			continue
		}
	}
	s.SignalReports(func(r *Report) {
		fmt.Println(r)
	})
}
Exemplo n.º 4
0
Arquivo: content.go Projeto: napsy/lab
func (s *srvraw) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path[:5] != "/raw/" {
		http.NotFound(w, r)
		return
	}
	switch r.Method {
	case "GET", "POST":
	default:
		http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
		return
	}
	path := r.URL.Path[4:]
	res := s.ws.Res(ws.NewId(path))
	if res == nil || res.Flag&(ws.FlagDir|ws.FlagIgnore) != 0 {
		http.NotFound(w, r)
		return
	}
	switch r.Method {
	case "GET":
		f, err := os.Open(path)
		if err != nil {
			http.NotFound(w, r)
			return
		}
		defer f.Close()
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
		_, err = io.Copy(w, f)
		if err != nil {
			log.Println(err)
		}
	case "POST":
		f, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0)
		if err != nil {
			http.NotFound(w, r)
			return
		}
		defer f.Close()
		_, err = io.Copy(f, r.Body)
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
	}
}
Exemplo n.º 5
0
Arquivo: gosrc.go Projeto: napsy/lab
func (s *Src) WorkOn(path string) error {
	flag := Working | Watching
	if d, f := filepath.Split(path); f == "..." {
		path = d
		flag |= Recursing
	}
	p, err := filepath.Abs(path)
	if err != nil {
		return err
	}
	id := ws.NewId(p)
	s.Lock()
	defer s.Unlock()
	pkg := s.getorcreate(id, p)
	pkg.Flag |= flag
	if pkg.Res != nil {
		workAll(s, pkg, make(map[ws.Id]*Pkg))
	}
	return nil
}