From f9e7fee47dc220951e2fb3064615ad9f5a30839f Mon Sep 17 00:00:00 2001 From: Seebs Date: Fri, 31 Jan 2020 09:48:05 -0600 Subject: [PATCH] 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). --- fragment.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fragment.go b/fragment.go index 22efb072e..39e14f1f6 100644 --- a/fragment.go +++ b/fragment.go @@ -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.