Merge pull request #183 from benbjohnson/copy-fallback

Add fallback for O_DIRECT in Tx.Copy().
master
Ben Johnson 2014-06-05 10:18:58 -06:00
commit 9ffb29787a
1 changed files with 9 additions and 4 deletions

11
tx.go
View File

@ -239,11 +239,16 @@ func (tx *Tx) close() {
// using the database while a copy is in progress. // using the database while a copy is in progress.
// Copy will write exactly tx.Size() bytes into the writer. // Copy will write exactly tx.Size() bytes into the writer.
func (tx *Tx) Copy(w io.Writer) error { func (tx *Tx) Copy(w io.Writer) error {
// Open reader on the database. var f *os.File
f, err := os.OpenFile(tx.db.path, os.O_RDONLY|odirect, 0) var err error
if err != nil {
// Attempt to open reader directly.
if f, err = os.OpenFile(tx.db.path, os.O_RDONLY|odirect, 0); err != nil {
// Fallback to a regular open if that doesn't work.
if f, err = os.OpenFile(tx.db.path, os.O_RDONLY, 0); err != nil {
return err return err
} }
}
// Copy the meta pages. // Copy the meta pages.
tx.db.metalock.Lock() tx.db.metalock.Lock()