Bug 368428 - "XUL FastLoad cache corruption when application running while upgrading" [r=biesi]

This commit is contained in:
Mike Hommey 2008-10-01 00:25:29 -05:00
Родитель 19819246b6
Коммит 75b421dbea
2 изменённых файлов: 20 добавлений и 2 удалений

Просмотреть файл

@ -127,6 +127,7 @@ nsJAR::nsJAR(): mManifestData(nsnull, nsnull, DeleteManifestEntry, nsnull, 10),
mReleaseTime(PR_INTERVAL_NO_TIMEOUT), mReleaseTime(PR_INTERVAL_NO_TIMEOUT),
mCache(nsnull), mCache(nsnull),
mLock(nsnull), mLock(nsnull),
mMtime(0),
mTotalItemsInManifest(0) mTotalItemsInManifest(0)
{ {
} }
@ -170,13 +171,16 @@ nsJAR::Open(nsIFile* zipFile)
if (mLock) return NS_ERROR_FAILURE; // Already open! if (mLock) return NS_ERROR_FAILURE; // Already open!
mZipFile = zipFile; mZipFile = zipFile;
nsresult rv = zipFile->GetLastModifiedTime(&mMtime);
if (NS_FAILED(rv)) return rv;
mLock = PR_NewLock(); mLock = PR_NewLock();
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
PRFileDesc *fd = OpenFile(); PRFileDesc *fd = OpenFile();
NS_ENSURE_TRUE(fd, NS_ERROR_FAILURE); NS_ENSURE_TRUE(fd, NS_ERROR_FAILURE);
nsresult rv = mZip.OpenArchive(fd); rv = mZip.OpenArchive(fd);
if (NS_FAILED(rv)) Close(); if (NS_FAILED(rv)) Close();
return rv; return rv;
@ -1117,6 +1121,7 @@ nsZipReaderCache::GetZip(nsIFile* zipFile, nsIZipReader* *result)
{ {
NS_ENSURE_ARG_POINTER(zipFile); NS_ENSURE_ARG_POINTER(zipFile);
nsresult rv; nsresult rv;
nsCOMPtr<nsIJAR> antiLockZipGrip;
nsAutoLock lock(mLock); nsAutoLock lock(mLock);
#ifdef ZIP_CACHE_HIT_RATE #ifdef ZIP_CACHE_HIT_RATE
@ -1127,15 +1132,23 @@ nsZipReaderCache::GetZip(nsIFile* zipFile, nsIZipReader* *result)
rv = zipFile->GetNativePath(path); rv = zipFile->GetNativePath(path);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
PRInt64 Mtime;
rv = zipFile->GetLastModifiedTime(&Mtime);
if (NS_FAILED(rv)) return rv;
nsCStringKey key(path); nsCStringKey key(path);
nsJAR* zip = static_cast<nsJAR*>(static_cast<nsIZipReader*>(mZips.Get(&key))); // AddRefs nsJAR* zip = static_cast<nsJAR*>(static_cast<nsIZipReader*>(mZips.Get(&key))); // AddRefs
if (zip) { if (zip && Mtime == zip->GetMtime()) {
#ifdef ZIP_CACHE_HIT_RATE #ifdef ZIP_CACHE_HIT_RATE
mZipCacheHits++; mZipCacheHits++;
#endif #endif
zip->ClearReleaseTime(); zip->ClearReleaseTime();
} }
else { else {
if (zip) {
antiLockZipGrip = zip;
mZips.Remove(&key);
}
zip = new nsJAR(); zip = new nsJAR();
if (zip == nsnull) if (zip == nsnull)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;

Просмотреть файл

@ -133,6 +133,10 @@ class nsJAR : public nsIZipReader, public nsIJAR
mCache = cache; mCache = cache;
} }
PRInt64 GetMtime() {
return mMtime;
}
protected: protected:
//-- Private data members //-- Private data members
nsCOMPtr<nsIFile> mZipFile; // The zip/jar file on disk nsCOMPtr<nsIFile> mZipFile; // The zip/jar file on disk
@ -144,6 +148,7 @@ class nsJAR : public nsIZipReader, public nsIJAR
PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries
nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in
PRLock* mLock; PRLock* mLock;
PRInt64 mMtime;
PRInt32 mTotalItemsInManifest; PRInt32 mTotalItemsInManifest;
//-- Private functions //-- Private functions