Merge pull request #19 from heyitsanthony/skip-freelist-read

do not read freelist if database opened readonly
pull/20/head
Anthony Romano 2017-08-11 10:11:03 -07:00 committed by GitHub
commit 2fe83be160
1 changed files with 5 additions and 1 deletions

6
db.go
View File

@ -240,6 +240,10 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
return nil, err return nil, err
} }
if db.readOnly {
return db, nil
}
db.freelist = newFreelist() db.freelist = newFreelist()
noFreeList := db.meta().freelist == pgidNoFreelist noFreeList := db.meta().freelist == pgidNoFreelist
if noFreeList { if noFreeList {
@ -253,7 +257,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
// Flush freelist when transitioning from no sync to sync so // Flush freelist when transitioning from no sync to sync so
// NoFreelistSync unaware boltdb can open the db later. // NoFreelistSync unaware boltdb can open the db later.
if !db.NoFreelistSync && noFreeList && ((mode & 0222) != 0) { if !db.NoFreelistSync && noFreeList {
tx, err := db.Begin(true) tx, err := db.Begin(true)
if tx != nil { if tx != nil {
err = tx.Commit() err = tx.Commit()