func (srv *Grande) Write(req *vtsrv.Req) { var f *os.File var n int s := srv.calcScore(req.Tc.Data) dname := fmt.Sprintf("%s/%02x/%02x", srv.topDir, s[0], s[1]) err := os.MkdirAll(dname, 0777) if err != nil { req.RespondError(err.Error()) return } f, err = os.OpenFile(srv.Name(s), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { req.RespondError(err.Error()) return } defer f.Close() n, err = f.Write(req.Tc.Data) if err != nil { req.RespondError(err.Error()) return } if n != len(req.Tc.Data) { req.RespondError("short write") return } req.RespondWrite(s) }
func (srv *Vtmap) Write(req *vtsrv.Req) { score := srv.calcScore(req.Tc.Data) strscore := string([]byte(score)) srv.Lock() if srv.htbl[strscore] == nil { block, err := srv.f.WriteBlock(req.Tc.Data) if err != nil { srv.Unlock() req.RespondError(err.Error()) return } srv.htbl[strscore] = block } srv.Unlock() req.RespondWrite(score) }
func (srv *Vtram) Write(req *vtsrv.Req) { b := srv.putBlock(req.Tc.Btype, req.Tc.Data) req.RespondWrite(b.score) }