From 4932a777effea9d58f9670b456f7601f153f0c6e Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Thu, 28 Apr 2016 16:07:02 -0400 Subject: [PATCH] Bug 1265621 - Add flag to track omnijar handle in nsJAR; r=aklotz Add a bool flag in nsJAR to track whether the zip handle came from omnijar. The old code compared pointers instead, but other patches in this bug made it no longer possible to do that. --- modules/libjar/nsJAR.cpp | 16 +++++++++++----- modules/libjar/nsJAR.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/libjar/nsJAR.cpp b/modules/libjar/nsJAR.cpp index 3c8c4d35294e..70bea8edade0 100644 --- a/modules/libjar/nsJAR.cpp +++ b/modules/libjar/nsJAR.cpp @@ -86,7 +86,8 @@ nsJAR::nsJAR(): mZip(new nsZipArchive()), mLock("nsJAR::mLock"), mMtime(0), mTotalItemsInManifest(0), - mOpened(false) + mOpened(false), + mIsOmnijar(false) { } @@ -141,6 +142,7 @@ nsJAR::Open(nsIFile* zipFile) RefPtr zip = mozilla::Omnijar::GetReader(zipFile); if (zip) { mZip = zip; + mIsOmnijar = true; return NS_OK; } return mZip->OpenArchive(zipFile); @@ -201,19 +203,23 @@ nsJAR::GetFile(nsIFile* *result) NS_IMETHODIMP nsJAR::Close() { + if (!mOpened) { + return NS_ERROR_FAILURE; // Never opened or already closed. + } + mOpened = false; mParsedManifest = false; mManifestData.Clear(); mGlobalStatus = JAR_MANIFEST_NOT_PARSED; mTotalItemsInManifest = 0; - RefPtr greOmni = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE); - RefPtr appOmni = mozilla::Omnijar::GetReader(mozilla::Omnijar::APP); - - if (mZip == greOmni || mZip == appOmni) { + if (mIsOmnijar) { + // Reset state, but don't close the omnijar because we did not open it. + mIsOmnijar = false; mZip = new nsZipArchive(); return NS_OK; } + return mZip->CloseArchive(); } diff --git a/modules/libjar/nsJAR.h b/modules/libjar/nsJAR.h index 243f03c16633..20057f67b471 100644 --- a/modules/libjar/nsJAR.h +++ b/modules/libjar/nsJAR.h @@ -113,6 +113,7 @@ class nsJAR final : public nsIZipReader int64_t mMtime; int32_t mTotalItemsInManifest; bool mOpened; + bool mIsOmnijar; nsresult ParseManifest(); void ReportError(const nsACString &aFilename, int16_t errorCode);