`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)
| 8 | // `dumpBucket` dumps all the data, including both key/value data |
| 9 | // and child buckets, from the source bucket into the target db file. |
| 10 | func 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 | |
| 30 | func cloneBucket(src *bolt.Bucket, dst *bolt.Bucket) error { |
| 31 | return src.ForEach(func(k, v []byte) error { |
no test coverage detected