Cleanup blockmap on update (fixes #889)

This commit is contained in:
Audrius Butkevicius
2014-10-22 15:24:11 +01:00
parent 198cbacc3e
commit 25bb55491a
3 changed files with 79 additions and 3 deletions

View File

@@ -90,6 +90,17 @@ func (m *BlockMap) Update(files []protocol.FileInfo) error {
return m.db.Write(batch, nil)
}
// Discard block map state, removing the given files
func (m *BlockMap) Discard(files []protocol.FileInfo) error {
batch := new(leveldb.Batch)
for _, file := range files {
for _, block := range file.Blocks {
batch.Delete(m.blockKey(block.Hash, file.Name))
}
}
return m.db.Write(batch, nil)
}
// Drop block map, removing all entries related to this block map from the db.
func (m *BlockMap) Drop() error {
batch := new(leveldb.Batch)