do not read freelist if database opened readonly

pull/19/head
Sokolov Yura aka funny_falcon 2015-08-15 13:13:23 +03:00 committed by Anthony Romano
parent 12923fe56c
commit ec37ce8e9b
1 changed files with 5 additions and 1 deletions

6
db.go
View File

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