diff options
author | Martin Kobetic <mkobetic@gmail.com> | 2014-05-21 15:43:11 +0000 |
---|---|---|
committer | Martin Kobetic <mkobetic@gmail.com> | 2014-05-21 15:43:11 +0000 |
commit | 0eda6c9f1522306b653a26f0a57f99fc4f287318 (patch) | |
tree | f344f2c163ecb88c1e2c7e1f48ccbb0cf5c8ccce | |
parent | move Copy and CopyFile from DB to Tx (diff) | |
download | dedo-0eda6c9f1522306b653a26f0a57f99fc4f287318.tar.gz dedo-0eda6c9f1522306b653a26f0a57f99fc4f287318.tar.xz |
add tx.Size() and ensure tx.Copy() copies exactly that many bytes
-rw-r--r-- | tx.go | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -73,6 +73,11 @@ func (tx *Tx) DB() *DB { return tx.db } +// Size returns current database size in bytes (as seen by this transaction) +func (tx *Tx) Size() int64 { + return int64(tx.meta.pgid) * int64(tx.db.pageSize) +} + // Writable returns whether the transaction can perform write operations. func (tx *Tx) Writable() bool { return tx.writable @@ -232,6 +237,7 @@ func (tx *Tx) close() { // Copy writes the entire database to a writer. // A reader transaction is maintained during the copy so it is safe to continue // using the database while a copy is in progress. +// Copy will write exactly tx.Size() bytes into the writer. func (tx *Tx) Copy(w io.Writer) error { // Open reader on the database. @@ -252,7 +258,7 @@ func (tx *Tx) Copy(w io.Writer) error { } // Copy data pages. - if _, err := io.Copy(w, f); err != nil { + if _, err := io.CopyN(w, f, tx.Size()-int64(tx.db.pageSize*2)); err != nil { _ = tx.Rollback() _ = f.Close() return err |