From 5d80c6450d8efdc34eeb41d2ae41dc61e1bf4bee Mon Sep 17 00:00:00 2001 From: Michal Novotny Date: Fri, 11 Aug 2017 12:30:59 +0200 Subject: [PATCH] Bug 1369051 - Assertion failure: !entry || !entry->IsFresh() in CacheIndex::UpdateIndex, r=honzab --- netwerk/cache2/CacheIndex.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/netwerk/cache2/CacheIndex.cpp b/netwerk/cache2/CacheIndex.cpp index 8d804505d569..7b754bdf2c9b 100644 --- a/netwerk/cache2/CacheIndex.cpp +++ b/netwerk/cache2/CacheIndex.cpp @@ -2806,11 +2806,16 @@ CacheIndex::BuildIndex() return; } + bool fileExists = false; nsCOMPtr file; { // Do not do IO under the lock. StaticMutexAutoUnlock unlock(sLock); rv = mDirEnumerator->GetNextFile(getter_AddRefs(file)); + + if (file) { + file->Exists(&fileExists); + } } if (mState == SHUTDOWN) { return; @@ -2829,6 +2834,12 @@ CacheIndex::BuildIndex() continue; } + if (!fileExists) { + LOG(("CacheIndex::BuildIndex() - File returned by the iterator was " + "removed in the meantime [name=%s]", leaf.get())); + continue; + } + SHA1Sum::Hash hash; rv = CacheFileIOManager::StrToHash(leaf, &hash); if (NS_FAILED(rv)) { @@ -2902,6 +2913,7 @@ CacheIndex::BuildIndex() LOG(("CacheIndex::BuildIndex() - CacheFile::InitEntryFromDiskData() " "failed, removing file. [name=%s]", leaf.get())); file->Remove(false); + entry->MarkRemoved(); } else { LOG(("CacheIndex::BuildIndex() - Added entry to index. [name=%s]", leaf.get())); @@ -3023,11 +3035,16 @@ CacheIndex::UpdateIndex() return; } + bool fileExists = false; nsCOMPtr file; { // Do not do IO under the lock. StaticMutexAutoUnlock unlock(sLock); rv = mDirEnumerator->GetNextFile(getter_AddRefs(file)); + + if (file) { + file->Exists(&fileExists); + } } if (mState == SHUTDOWN) { return; @@ -3046,6 +3063,12 @@ CacheIndex::UpdateIndex() continue; } + if (!fileExists) { + LOG(("CacheIndex::UpdateIndex() - File returned by the iterator was " + "removed in the meantime [name=%s]", leaf.get())); + continue; + } + SHA1Sum::Hash hash; rv = CacheFileIOManager::StrToHash(leaf, &hash); if (NS_FAILED(rv)) {