Merge pull request #193 from ranbochen/fix-#191

Fix #191
This commit is contained in:
Fabian Reinartz 2017-11-03 20:20:01 +01:00 committed by GitHub
commit 296faccf2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

21
db.go
View file

@ -379,6 +379,27 @@ func (db *DB) compact() (changes bool, err error) {
} }
changes = true changes = true
// close blocks in plan so that we can remove files.
var blocks []*Block
db.mtx.Lock()
oldBlocks := db.blocks
for _, b := range oldBlocks {
keep := true
for _, pd := range plan {
if pd == b.Dir() {
keep = false
break
}
}
if keep {
blocks = append(blocks, b)
} else {
b.Close()
}
}
db.blocks = blocks
db.mtx.Unlock()
for _, pd := range plan { for _, pd := range plan {
if err := os.RemoveAll(pd); err != nil { if err := os.RemoveAll(pd); err != nil {
return changes, errors.Wrap(err, "delete compacted block") return changes, errors.Wrap(err, "delete compacted block")