MCPcopy
hub / github.com/etcd-io/bbolt / dumpBucket

Function dumpBucket

utils_test.go:10–28  ·  view source on GitHub ↗

`dumpBucket` dumps all the data, including both key/value data and child buckets, from the source bucket into the target db file.

(srcBucketName []byte, srcBucket *bolt.Bucket, dstFilename string)

Source from the content-addressed store, hash-verified

8// `dumpBucket` dumps all the data, including both key/value data
9// and child buckets, from the source bucket into the target db file.
10func dumpBucket(srcBucketName []byte, srcBucket *bolt.Bucket, dstFilename string) error {
11 common.Assert(len(srcBucketName) != 0, "source bucket name can't be empty")
12 common.Assert(srcBucket != nil, "the source bucket can't be nil")
13 common.Assert(len(dstFilename) != 0, "the target file path can't be empty")
14
15 dstDB, err := bolt.Open(dstFilename, 0600, nil)
16 if err != nil {
17 return err
18 }
19 defer dstDB.Close()
20
21 return dstDB.Update(func(tx *bolt.Tx) error {
22 dstBucket, err := tx.CreateBucket(srcBucketName)
23 if err != nil {
24 return err
25 }
26 return cloneBucket(srcBucket, dstBucket)
27 })
28}
29
30func cloneBucket(src *bolt.Bucket, dst *bolt.Bucket) error {
31 return src.ForEach(func(k, v []byte) error {

Callers 1

TestTx_MoveBucketFunction · 0.85

Calls 5

AssertFunction · 0.92
cloneBucketFunction · 0.85
UpdateMethod · 0.80
CloseMethod · 0.45
CreateBucketMethod · 0.45

Tested by

no test coverage detected