From 09c32538fba0b626191ebf687c50ce75b4d38e7d Mon Sep 17 00:00:00 2001 From: Tom Tung Date: Wed, 18 Dec 2019 15:50:18 +0000 Subject: [PATCH] Bug 1594075 - P1 - Ignore the unknown directories in origin directories; r=janv Differential Revision: https://phabricator.services.mozilla.com/D51873 --HG-- extra : moz-landing-system : lando --- dom/quota/ActorsParent.cpp | 16 ++- dom/quota/test/unit/test_unknownFiles.js | 129 ++++++++++------------- 2 files changed, 62 insertions(+), 83 deletions(-) diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 498d9e8d9a2d..9532d201a72b 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -5180,10 +5180,6 @@ nsresult QuotaManager::InitializeOrigin(PersistenceType aPersistenceType, Client::Type clientType; bool ok = Client::TypeFromText(leafName, clientType, fallible); if (!ok) { - UNKNOWN_FILE_WARNING(leafName); - REPORT_TELEMETRY_INIT_ERR(kQuotaInternalError, Ori_UnexpectedClient); - RECORD_IN_NIGHTLY(statusKeeper, NS_ERROR_UNEXPECTED); - // Our upgrade process should have attempted to delete the deprecated // client directory and failed to upgrade if it could not be deleted. So // if we're here, either a) there's a bug in our code or b) a user copied @@ -5200,10 +5196,13 @@ nsresult QuotaManager::InitializeOrigin(PersistenceType aPersistenceType, CONTINUE_IN_NIGHTLY_RETURN_IN_OTHERS(rv); } - MOZ_DIAGNOSTIC_ASSERT(true, "Found a deprecated client"); + MOZ_DIAGNOSTIC_ASSERT(false, "Found a deprecated client"); } - CONTINUE_IN_NIGHTLY_RETURN_IN_OTHERS(NS_ERROR_UNEXPECTED); + // Unknown directories during initialization are now allowed. Just warn if + // we find them. + UNKNOWN_FILE_WARNING(leafName); + continue; } UsageInfo usageInfo; @@ -9015,10 +9014,9 @@ nsresult QuotaUsageRequestBase::GetUsageForOrigin( Client::Type clientType; bool ok = Client::TypeFromText(leafName, clientType, fallible); if (!ok) { + // Unknown directories during getting usage for an origin (even for an + // uninitialized origin) are now allowed. Just warn if we find them. UNKNOWN_FILE_WARNING(leafName); - if (!initialized) { - return NS_ERROR_UNEXPECTED; - } continue; } diff --git a/dom/quota/test/unit/test_unknownFiles.js b/dom/quota/test/unit/test_unknownFiles.js index 36ebfcaadaf9..e46c89205957 100644 --- a/dom/quota/test/unit/test_unknownFiles.js +++ b/dom/quota/test/unit/test_unknownFiles.js @@ -29,7 +29,7 @@ function* testSteps() { dir: false, }; - const unknownClient = { + const unknownOriginDirectory = { path: "storage/permanent/chrome/foo", dir: true, }; @@ -94,6 +94,7 @@ function* testSteps() { "Initialization succeeded even though there are unknown files in " + "repositories" ); + ok(request.result === true, "The origin directory was created"); info("Clearing origin"); @@ -109,7 +110,10 @@ function* testSteps() { ok(request.resultCode == NS_OK, "Clearing succeeded"); - info("Stage 3 - Testing unknown origin files found during origin init"); + info( + "Stage 3 - Testing unknown origin files and unknown origin directories " + + "found during origin init" + ); info("Initializing"); @@ -118,99 +122,76 @@ function* testSteps() { ok(request.resultCode == NS_OK, "Initialization succeeded"); - info("Creating unknown file"); + for (let unknownFile of [unknownOriginFile, unknownOriginDirectory]) { + info("Creating unknown file"); - file = createFile(unknownOriginFile); + file = createFile(unknownFile); - info("Initializing origin"); + info("Initializing origin"); - request = initStorageAndChromeOrigin("persistent", continueToNextStepSync); - yield undefined; + request = initStorageAndChromeOrigin("persistent", continueToNextStepSync); + yield undefined; - ok( - request.resultCode == NS_OK, - "Initialization succeeded even though there are unknown files in origin " + - "directories" - ); + ok( + request.resultCode == NS_OK, + "Initialization succeeded even though there are unknown files or " + + "directories in origin directories" + ); + ok(request.result === false, "The origin directory wasn't created"); - info("Getting usage"); + info("Getting usage"); - request = getCurrentUsage(continueToNextStepSync); - yield undefined; + request = getCurrentUsage(continueToNextStepSync); + yield undefined; - ok( - request.resultCode == NS_OK, - "Get usage succeeded even though there are unknown files in origin " + - "directories" - ); + ok( + request.resultCode == NS_OK, + "Get usage succeeded even though there are unknown files or directories" + + "in origin directories" + ); + ok(request.result, "The request result is not null"); + ok(request.result.usage === 0, "The usage was 0"); + ok(request.result.fileUsage === 0, "The fileUsage was 0"); - info("Clearing origin"); + file.remove(/* recursive */ false); - request = clearChromeOrigin(continueToNextStepSync); - yield undefined; + info("Getting usage"); - ok(request.resultCode == NS_OK, "Clearing succeeded"); + request = getCurrentUsage(continueToNextStepSync); + yield undefined; - info("Stage 4 - Testing unknown client files found during origin init"); + ok(request.resultCode == NS_OK, "Get usage succeeded"); + ok(request.result, "The request result is not null"); + ok(request.result.usage === 0, "The usage was 0"); + ok(request.result.fileUsage === 0, "The fileUsage was 0"); - info("Creating unknown file"); + info("Initializing origin"); - file = createFile(unknownClient); + request = initStorageAndChromeOrigin("persistent", continueToNextStepSync); + yield undefined; - info("Initializing origin"); + ok(request.resultCode == NS_OK, "Initialization succeeded"); + ok(request.result === false, "The origin directory wasn't created"); - request = initStorageAndChromeOrigin("persistent", continueToNextStepSync); - yield undefined; + file = createFile(unknownFile); - ok(request.resultCode == NS_ERROR_UNEXPECTED, "Initialization failed"); - ok(request.result === null, "The request result is null"); + info("Getting usage"); - info("Getting usage"); + request = getCurrentUsage(continueToNextStepSync); + yield undefined; - request = getCurrentUsage(continueToNextStepSync); - yield undefined; + ok(request.resultCode == NS_OK, "Get usage succeeded"); + ok(request.result, "The request result is not null"); + ok(request.result.usage === 0, "The usage was 0"); + ok(request.result.fileUsage === 0, "The fileUsage was 0"); - ok(request.resultCode == NS_ERROR_UNEXPECTED, "Initialization failed"); - ok(request.result === null, "The request result is null"); + info("Clearing origin"); - file.remove(/* recursive */ false); + request = clearChromeOrigin(continueToNextStepSync); + yield undefined; - info("Getting usage"); - - request = getCurrentUsage(continueToNextStepSync); - yield undefined; - - ok(request.resultCode == NS_OK, "Get usage succeeded"); - - info("Clearing origin"); - - request = clearChromeOrigin(continueToNextStepSync); - yield undefined; - - ok(request.resultCode == NS_OK, "Clearing succeeded"); - - info("Initializing origin"); - - request = initStorageAndChromeOrigin("persistent", continueToNextStepSync); - yield undefined; - - ok(request.resultCode == NS_OK, "Initialization succeeded"); - - file = createFile(unknownClient); - - info("Getting usage"); - - request = getCurrentUsage(continueToNextStepSync); - yield undefined; - - ok(request.resultCode == NS_OK, "Get usage succeeded"); - - info("Clearing origin"); - - request = clearChromeOrigin(continueToNextStepSync); - yield undefined; - - ok(request.resultCode == NS_OK, "Clearing succeeded"); + ok(request.resultCode == NS_OK, "Clearing succeeded"); + } info("Clearing");