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
parent 7e406efef1
commit a4003e2ade
2 changed files with 20 additions and 2 deletions

View File

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

View File

@ -133,6 +133,10 @@ class nsJAR : public nsIZipReader, public nsIJAR
mCache = cache;
}
PRInt64 GetMtime() {
return mMtime;
}
protected:
//-- Private data members
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
nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in
PRLock* mLock;
PRInt64 mMtime;
PRInt32 mTotalItemsInManifest;
//-- Private functions