From 0517d3721cee2141eba6d517267f5250df7e96a9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 6 Feb 2016 19:49:33 -0800 Subject: [PATCH] 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. --- Core/FileLoaders/DiskCachingFileLoader.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Core/FileLoaders/DiskCachingFileLoader.cpp b/Core/FileLoaders/DiskCachingFileLoader.cpp index 91aad667e5..e346cf35fe 100644 --- a/Core/FileLoaders/DiskCachingFileLoader.cpp +++ b/Core/FileLoaders/DiskCachingFileLoader.cpp @@ -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()); }