Correct recovery of locked disk cache files.

We were keeping the index when creating a new file, rather than clearing
it.  Additionally, flush before all reads - in case of overlap.
This commit is contained in:
Unknown W. Brackets 2016-02-06 19:49:33 -08:00
parent 609c8eb29f
commit 0517d3721c

View file

@ -422,6 +422,10 @@ bool DiskCachingFileLoaderCache::ReadBlockData(u8 *dest, BlockInfo &info, size_t
}
s64 blockOffset = GetBlockOffset(info.block);
// Before we read, make sure the buffers are flushed.
// We might be trying to read an area we've recently written.
fflush(f_);
bool failed = false;
#ifdef ANDROID
if (lseek64(fd_, blockOffset, SEEK_SET) != blockOffset) {
@ -615,6 +619,7 @@ void DiskCachingFileLoaderCache::CreateCacheFile(const std::string &path) {
}
indexCount_ = (filesize_ + blockSize_ - 1) / blockSize_;
index_.clear();
index_.resize(indexCount_);
blockIndexLookup_.resize(maxBlocks_);
memset(&blockIndexLookup_[0], INVALID_INDEX, maxBlocks_ * sizeof(blockIndexLookup_[0]));
@ -623,6 +628,10 @@ void DiskCachingFileLoaderCache::CreateCacheFile(const std::string &path) {
CloseFileHandle();
return;
}
if (fflush(f_) != 0) {
CloseFileHandle();
return;
}
INFO_LOG(LOADER, "Created new disk cache file for %s", origPath_.c_str());
}