diff --git a/toolkit/components/url-classifier/Classifier.cpp b/toolkit/components/url-classifier/Classifier.cpp index 50c554d3230e..001a78e0b668 100644 --- a/toolkit/components/url-classifier/Classifier.cpp +++ b/toolkit/components/url-classifier/Classifier.cpp @@ -149,6 +149,28 @@ Classifier::SetupPathNames() return NS_OK; } +nsresult +Classifier::CreateStoreDirectory() +{ + // Ensure the safebrowsing directory exists. + bool storeExists; + nsresult rv = mStoreDirectory->Exists(&storeExists); + NS_ENSURE_SUCCESS(rv, rv); + + if (!storeExists) { + rv = mStoreDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755); + NS_ENSURE_SUCCESS(rv, rv); + } else { + bool storeIsDir; + rv = mStoreDirectory->IsDirectory(&storeIsDir); + NS_ENSURE_SUCCESS(rv, rv); + if (!storeIsDir) + return NS_ERROR_FILE_DESTINATION_NOT_DIR; + } + + return NS_OK; +} + nsresult Classifier::Open(nsIFile& aCacheDirectory) { @@ -169,22 +191,10 @@ Classifier::Open(nsIFile& aCacheDirectory) rv = RecoverBackups(); NS_ENSURE_SUCCESS(rv, rv); - // Ensure the safebrowsing directory exists. - bool storeExists; - rv = mStoreDirectory->Exists(&storeExists); + // Make sure the main store directory exists. + rv = CreateStoreDirectory(); NS_ENSURE_SUCCESS(rv, rv); - if (!storeExists) { - rv = mStoreDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755); - NS_ENSURE_SUCCESS(rv, rv); - } else { - bool storeIsDir; - rv = mStoreDirectory->IsDirectory(&storeIsDir); - NS_ENSURE_SUCCESS(rv, rv); - if (!storeIsDir) - return NS_ERROR_FILE_DESTINATION_NOT_DIR; - } - mCryptoHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -219,6 +229,8 @@ Classifier::Reset() mBackupDirectory->Remove(true); mToDeleteDirectory->Remove(true); + CreateStoreDirectory(); + mTableFreshness.Clear(); RegenActiveTables(); } diff --git a/toolkit/components/url-classifier/Classifier.h b/toolkit/components/url-classifier/Classifier.h index ff11d91fca77..bacad2e90cc8 100644 --- a/toolkit/components/url-classifier/Classifier.h +++ b/toolkit/components/url-classifier/Classifier.h @@ -71,6 +71,7 @@ public: PrefixArray* aNoiseEntries); private: void DropStores(); + nsresult CreateStoreDirectory(); nsresult SetupPathNames(); nsresult RecoverBackups(); nsresult CleanToDelete(); diff --git a/toolkit/components/url-classifier/tests/unit/test_streamupdater.js b/toolkit/components/url-classifier/tests/unit/test_streamupdater.js index c934890dba0e..24254cde1f82 100644 --- a/toolkit/components/url-classifier/tests/unit/test_streamupdater.js +++ b/toolkit/components/url-classifier/tests/unit/test_streamupdater.js @@ -454,7 +454,7 @@ function run_test() testValidForwardMAC, testInvalidForwardMAC, testNoForwardMAC, - testRekey, + testRekey ]); }