| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| func RunInTransaction(st Store, fn func(st StoreReadWriter) error) error { |
| // TODO(rogulenko): We should eventually give up with |
| // ErrConcurrentTransaction. |
| // TODO(rogulenko): Fail on RPC errors. |
| tx := st.NewTransaction() |
| if err := fn(tx); err != nil { |
| if verror.ErrorID(err) == ErrConcurrentTransaction.ID { |
| // CopyBytes copies elements from a source slice into a destination slice. |
| // The returned slice may be a sub-slice of dst if dst was large enough to hold |
| // src. Otherwise, a newly allocated slice will be returned. |
| // TODO(rogulenko): add some tests. |
| func CopyBytes(dst, src []byte) []byte { |
| dst = make([]byte, newlen) |