diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index cab6fe792b8..b2c3db07cda 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -3360,10 +3360,6 @@ nsXULDocument::SetDir(const nsAReadableString& aDirection) NS_IMETHODIMP nsXULDocument::GetPopupNode(nsIDOMNode** aNode) { -#ifdef DEBUG_dr - printf("dr :: nsXULDocument::GetPopupNode\n"); -#endif - nsresult rv; // get focus controller @@ -3380,10 +3376,6 @@ nsXULDocument::GetPopupNode(nsIDOMNode** aNode) NS_IMETHODIMP nsXULDocument::SetPopupNode(nsIDOMNode* aNode) { -#ifdef DEBUG_dr - printf("dr :: nsXULDocument::SetPopupNode\n"); -#endif - nsresult rv; // get focus controller @@ -4876,10 +4868,10 @@ nsXULDocument::StartFastLoad() rv = fastLoadService->NewInputStream(input, getter_AddRefs(objectInput)); if (NS_SUCCEEDED(rv)) { - nsCOMPtr - readControl(do_QueryInterface(objectInput)); - if (readControl) { - if (gChecksumXULFastLoadFile) { + if (gChecksumXULFastLoadFile) { + nsCOMPtr + readControl(do_QueryInterface(objectInput)); + if (readControl) { // Verify checksum, using the fastLoadService's checksum // cache to avoid computing more than once per session. PRUint32 checksum; @@ -4890,21 +4882,9 @@ nsXULDocument::StartFastLoad() readControl, &verified); if (NS_SUCCEEDED(rv) && verified != checksum) { - NS_WARNING("bad FastLoad file checksum"); - rv = NS_ERROR_FAILURE; - } - } - } - - if (NS_SUCCEEDED(rv)) { - // Check dependencies, fail if any is newer than file. - PRTime dtime, mtime; - rv = fastLoadService->MaxDependencyModifiedTime(readControl, - &dtime); - if (NS_SUCCEEDED(rv)) { - rv = file->GetLastModificationDate(&mtime); - if (NS_SUCCEEDED(rv) && LL_CMP(mtime, <, dtime)) { - NS_WARNING("FastLoad file out of date"); +#ifdef DEBUG + printf("bad FastLoad file checksum\n"); +#endif rv = NS_ERROR_FAILURE; } } @@ -4919,7 +4899,9 @@ nsXULDocument::StartFastLoad() rv = objectInput->Read32(&version); if (NS_SUCCEEDED(rv)) { if (version != XUL_FASTLOAD_FILE_VERSION) { - NS_WARNING("bad FastLoad file version"); +#ifdef DEBUG + printf("bad FastLoad file version\n"); +#endif rv = NS_ERROR_UNEXPECTED; } else { nsXPIDLCString fileChromePath; @@ -4963,13 +4945,26 @@ nsXULDocument::StartFastLoad() nsCOMPtr objectOutput; rv = fastLoadService->NewOutputStream(output, getter_AddRefs(objectOutput)); - if (NS_FAILED(rv)) return rv; + if (NS_SUCCEEDED(rv)) { + rv = objectOutput->Write32(XUL_FASTLOAD_FILE_VERSION); + if (NS_SUCCEEDED(rv)) + rv = objectOutput->WriteStringZ(chromePath); + } - rv = objectOutput->Write32(XUL_FASTLOAD_FILE_VERSION); - if (NS_FAILED(rv)) return rv; + // Remove here even though some errors above will lead to a FastLoad + // file invalidation. Other errors (failure to note the dependency on + // installed-chrome.txt, e.g.) will not cause invalidation, and we may + // as well tidy up now. + if (NS_FAILED(rv)) { + if (objectOutput) + objectOutput->Close(); + else + output->Close(); + xio->mOutputStream = nsnull; - rv = objectOutput->WriteStringZ(chromePath); - if (NS_FAILED(rv)) return rv; + file->Remove(PR_FALSE); + return rv; + } fastLoadService->SetOutputStream(objectOutput); } @@ -5976,6 +5971,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader, const char* string) { // print a load error on bad status + // XXXbe shouldn't we do this only #ifdef DEBUG if (NS_FAILED(aStatus)) { nsCOMPtr request; aLoader->GetRequest(getter_AddRefs(request)); diff --git a/mozilla/xpcom/io/nsBinaryStream.cpp b/mozilla/xpcom/io/nsBinaryStream.cpp index af03885e2c3..78afd976df3 100644 --- a/mozilla/xpcom/io/nsBinaryStream.cpp +++ b/mozilla/xpcom/io/nsBinaryStream.cpp @@ -410,7 +410,7 @@ nsBinaryInputStream::Read64(PRUint64* a64) rv = Read(NS_REINTERPRET_CAST(char*, a64), sizeof *a64, &bytesRead); if (NS_FAILED(rv)) return rv; - if (bytesRead != sizeof a64) + if (bytesRead != sizeof *a64) return NS_ERROR_FAILURE; *a64 = NS_SWAP64(*a64); return rv; diff --git a/mozilla/xpcom/io/nsFastLoadFile.cpp b/mozilla/xpcom/io/nsFastLoadFile.cpp index 18b4c9e9214..43316a67932 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.cpp +++ b/mozilla/xpcom/io/nsFastLoadFile.cpp @@ -731,11 +731,31 @@ nsFastLoadFileReader::ReadFooter(nsFastLoadFooter *aFooter) if (NS_FAILED(rv)) return rv; + PRInt64 fastLoadMtime; + rv = Read64(NS_REINTERPRET_CAST(PRUint64*, &fastLoadMtime)); + if (NS_FAILED(rv)) + return rv; + nsCOMPtr file; rv = NS_NewLocalFile(filename, PR_TRUE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; + PRInt64 currentMtime; + rv = file->GetLastModificationDate(¤tMtime); + if (NS_FAILED(rv)) + return rv; + + if (LL_NE(fastLoadMtime, currentMtime)) { +#ifdef DEBUG + nsXPIDLCString path; + file->GetPath(getter_Copies(path)); + printf("%s mtime changed, invalidating FastLoad file\n", + (const char *)path); +#endif + return NS_ERROR_FAILURE; + } + rv = readDeps->AppendElement(file); if (NS_FAILED(rv)) return rv; @@ -1461,6 +1481,10 @@ nsFastLoadFileWriter::EndMuxedDocument(nsISupports* aURI) return NS_OK; } +struct nsDependencyMapEntry : public nsStringMapEntry { + PRInt64 mLastModified; +}; + NS_IMETHODIMP nsFastLoadFileWriter::AddDependency(nsIFile* aFile) { @@ -1469,8 +1493,8 @@ nsFastLoadFileWriter::AddDependency(nsIFile* aFile) if (NS_FAILED(rv)) return rv; - nsStringMapEntry* entry = - NS_STATIC_CAST(nsStringMapEntry*, + nsDependencyMapEntry* entry = + NS_STATIC_CAST(nsDependencyMapEntry*, PL_DHashTableOperate(&mDependencyMap, path.get(), PL_DHASH_ADD)); if (!entry) @@ -1482,8 +1506,9 @@ nsFastLoadFileWriter::AddDependency(nsIFile* aFile) if (!tmp) return NS_ERROR_OUT_OF_MEMORY; entry->mString = NS_REINTERPRET_CAST(const char*, tmp); + rv = aFile->GetLastModificationDate(&entry->mLastModified); } - return NS_OK; + return rv; } nsresult @@ -1661,10 +1686,12 @@ nsFastLoadFileWriter::DependencyMapEnumerate(PLDHashTable *aTable, { nsFastLoadFileWriter* writer = NS_REINTERPRET_CAST(nsFastLoadFileWriter*, aTable->data); - nsStringMapEntry* entry = NS_STATIC_CAST(nsStringMapEntry*, aHdr); + nsDependencyMapEntry* entry = NS_STATIC_CAST(nsDependencyMapEntry*, aHdr); nsresult* rvp = NS_REINTERPRET_CAST(nsresult*, aData); *rvp = writer->WriteStringZ(entry->mString); + if (NS_SUCCEEDED(*rvp)) + *rvp = writer->Write64(entry->mLastModified); return NS_FAILED(*rvp) ? PL_DHASH_STOP :PL_DHASH_NEXT; } @@ -1764,7 +1791,7 @@ nsFastLoadFileWriter::Init() } if (!PL_DHashTableInit(&mDependencyMap, &strmap_DHashTableOps, (void *)this, - sizeof(nsStringMapEntry), PL_DHASH_MIN_SIZE)) { + sizeof(nsDependencyMapEntry), PL_DHASH_MIN_SIZE)) { mDependencyMap.ops = nsnull; return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/xpcom/io/nsFastLoadFile.h b/mozilla/xpcom/io/nsFastLoadFile.h index 1d0a39b464c..cf84b8cd181 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.h +++ b/mozilla/xpcom/io/nsFastLoadFile.h @@ -141,7 +141,7 @@ typedef PRUint32 NSFastLoadOID; // nsFastLoadFooter::mObjectMap index #define MFL_FILE_VERSION_0 0 #define MFL_FILE_VERSION_1 1000 -#define MFL_FILE_VERSION 2 // experimental, muxed doc support +#define MFL_FILE_VERSION 3 // fix to store dependency mtimes /** * Compute Fletcher's 16-bit checksum over aLength bytes starting at aBuffer, diff --git a/mozilla/xpcom/io/nsFastLoadService.cpp b/mozilla/xpcom/io/nsFastLoadService.cpp index 7dcdde05381..85f306a3909 100644 --- a/mozilla/xpcom/io/nsFastLoadService.cpp +++ b/mozilla/xpcom/io/nsFastLoadService.cpp @@ -351,38 +351,6 @@ nsFastLoadService::AddDependency(nsIFile* aFile) return control->AddDependency(aFile); } -NS_IMETHODIMP -nsFastLoadService::MaxDependencyModifiedTime(nsIFastLoadReadControl* aControl, - PRTime *aTime) -{ - *aTime = LL_ZERO; - - nsAutoLock lock(mLock); - - nsCOMPtr dependencies; - nsresult rv = aControl->GetDependencies(getter_AddRefs(dependencies)); - if (NS_FAILED(rv)) - return rv; - - PRBool more; - while (NS_SUCCEEDED(dependencies->HasMoreElements(&more)) && more) { - nsCOMPtr file; - dependencies->GetNext(getter_AddRefs(file)); - if (!file) - return NS_ERROR_UNEXPECTED; - - PRTime lastModifiedTime; - rv = file->GetLastModificationDate(&lastModifiedTime); - if (NS_FAILED(rv)) - return rv; - - if (LL_CMP(*aTime, <, lastModifiedTime)) - *aTime = lastModifiedTime; - } - - return NS_OK; -} - NS_IMETHODIMP nsFastLoadService::ComputeChecksum(nsIFile* aFile, nsIFastLoadReadControl* aControl, diff --git a/mozilla/xpcom/io/nsIFastLoadService.idl b/mozilla/xpcom/io/nsIFastLoadService.idl index 16b065c3466..af91d1f7607 100644 --- a/mozilla/xpcom/io/nsIFastLoadService.idl +++ b/mozilla/xpcom/io/nsIFastLoadService.idl @@ -85,7 +85,6 @@ interface nsIFastLoadService : nsISupports void endMuxedDocument(in nsISupports aURI); void addDependency(in nsIFile aFile); - PRTime maxDependencyModifiedTime(in nsIFastLoadReadControl aControl); PRUint32 computeChecksum(in nsIFile aFile, in nsIFastLoadReadControl aControl);