func (l *internalLevelDBStore) updateRootByKey(key []byte, current, last ref.Ref) bool { l.mu.Lock() defer l.mu.Unlock() if last != l.rootByKey(key) { return false } // Sync: true write option should fsync memtable data to disk err := l.db.Put(key, []byte(current.String()), &opt.WriteOptions{Sync: true}) d.Chk.NoError(err) return true }
func (h *HTTPStore) requestRef(r ref.Ref, method string, body io.Reader) *http.Response { url := *h.host url.Path = httprouter.CleanPath(h.host.Path + constants.RefPath) if !r.IsEmpty() { url.Path = path.Join(url.Path, r.String()) } header := http.Header{} if body != nil { header.Set("Content-Type", "application/octet-stream") } req := h.newRequest(method, url.String(), body, header) res, err := h.httpClient.Do(req) d.Chk.NoError(err) return res }
func (h *HTTPStore) requestRoot(method string, current, last ref.Ref) *http.Response { u := *h.host u.Path = httprouter.CleanPath(h.host.Path + constants.RootPath) if method == "POST" { d.Exp.False(current.IsEmpty()) params := url.Values{} params.Add("last", last.String()) params.Add("current", current.String()) u.RawQuery = params.Encode() } req := h.newRequest(method, u.String(), nil, nil) res, err := h.httpClient.Do(req) d.Chk.NoError(err) return res }
func assertInputInStore(input string, ref ref.Ref, s ChunkStore, assert *assert.Assertions) { chunk := s.Get(ref) assert.False(chunk.IsEmpty(), "Shouldn't get empty chunk for %s", ref.String()) assert.Equal(input, string(chunk.Data())) }
func assertInputNotInStore(input string, ref ref.Ref, s ChunkStore, assert *assert.Assertions) { data := s.Get(ref) assert.Nil(data, "Shouldn't have gotten data for %s", ref.String()) }
func (w *jsonArrayWriter) writeRef(r ref.Ref) { w.write(r.String()) }
// ToTag replaces "-" characters in s with "_", so it can be used in a Go identifier. // TODO: replace other illegal chars as well? func ToTag(r ref.Ref) string { return strings.Replace(r.String()[0:12], "-", "_", -1) }
// RefToJSIdentfierName generates an identifier name representing a Ref. ie. `sha1_abc1234`. func (gen *Generator) RefToJSIdentfierName(r ref.Ref) string { return strings.Replace(r.String(), "-", "_", 1)[0:12] }