don't mark a source as changed before we've finished remapping

Also, check the remap operation for errors, and if an error occurs,
try to remap to nil (which shouldn't be able to fail).
This commit is contained in:
Seebs 2020-01-31 09:48:05 -06:00 committed by Matt Jaffee
parent ebab831a43
commit f9e7fee47d
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -296,13 +296,22 @@ func (f *fragment) applyStorage(data []byte, file *os.File, newGen generation, m
// Tell storage to prefer mapping if and only if we think the data
// is mmapped and valid.
f.storage.PreferMapping(mapped)
f.storage.SetSource(newGen)
// RemapRoaringStorage will fix any mapped containers to point either
// to the provided data (if PreferMapping was called with true and
// data is provided and there's a corresponding container) or to
// allocated storage, so when it's done, there's nothing in it that
// is mapped to anything *other than* the provided data.
return f.storage.RemapRoaringStorage(data)
mapped, err := f.storage.RemapRoaringStorage(data)
if err != nil {
// OOPS! something went wrong, we don't know why, we can't
// sanely recover from that.
_, _ = f.storage.RemapRoaringStorage(nil)
mapped = false
f.storage.SetSource(nil)
} else {
f.storage.SetSource(newGen)
}
return mapped, err
}
// openStorage opens the storage bitmap.