Beispiel #1
0
// Stat returns metadata about the file or directory at path,
// in revision *storeRev. If storeRev is nil, uses the current
// revision.
func (c *Conn) Stat(path string, storeRev *int64) (len int, fileRev int64, err error) {
	var t txn
	t.req.Verb = newRequest_Verb(request_STAT)
	t.req.Path = &path
	t.req.Rev = storeRev

	err = c.call(&t)
	if err != nil {
		return 0, 0, err
	}

	return int(proto.GetInt32(t.resp.Len)), proto.GetInt64(t.resp.Rev), nil
}
Beispiel #2
0
// Returns the body and revision of the file at path,
// as of store revision *rev.
// If rev is nil, uses the current state.
func (c *Conn) Get(file string, rev *int64) ([]byte, int64, error) {
	var t txn
	t.req.Verb = newRequest_Verb(request_GET)
	t.req.Path = &file
	t.req.Rev = rev

	err := c.call(&t)
	if err != nil {
		return nil, 0, err
	}

	return t.resp.Value, proto.GetInt64(t.resp.Rev), nil
}
Beispiel #3
0
// Sets the contents of file to body, if it hasn't been modified since oldRev.
func (c *Conn) Set(file string, oldRev int64, body []byte) (newRev int64, err error) {
	var t txn
	t.req.Verb = newRequest_Verb(request_SET)
	t.req.Path = &file
	t.req.Value = body
	t.req.Rev = &oldRev

	err = c.call(&t)
	if err != nil {
		return
	}

	return proto.GetInt64(t.resp.Rev), nil
}
Beispiel #4
0
// protoToKey converts a Reference proto to a *Key.
func protoToKey(r *pb.Reference) (k *Key, err error) {
	appID := proto.GetString(r.App)
	namespace := proto.GetString(r.NameSpace)
	for _, e := range r.Path.Element {
		k = &Key{
			kind:      proto.GetString(e.Type),
			stringID:  proto.GetString(e.Name),
			intID:     proto.GetInt64(e.Id),
			parent:    k,
			appID:     appID,
			namespace: namespace,
		}
		if !k.valid() {
			return nil, ErrInvalidKey
		}
	}
	return
}