From 7b660959059fa92317026ed4d91ccd1fcdcf721e Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Thu, 11 Sep 2014 16:57:10 -0700 Subject: [PATCH] Bug 1062984 - Make directory service query for bookmark migration more resilient; r=fabrice --HG-- extra : rebase_source : 54d6ba208d20053ae9888baf8450f2c251c7900c --- b2g/components/B2GAppMigrator.js | 55 ++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/b2g/components/B2GAppMigrator.js b/b2g/components/B2GAppMigrator.js index cdfadb83e6c5..ecb053e63b4f 100644 --- a/b2g/components/B2GAppMigrator.js +++ b/b2g/components/B2GAppMigrator.js @@ -15,6 +15,9 @@ const Cu = Components.utils; const kMigrationMessageName = "webapps-before-update-merge"; +const kIDBDirType = "indexedDBPDir"; +const kProfileDirType = "ProfD"; + Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/FileUtils.jsm"); @@ -42,26 +45,60 @@ B2GAppMigrator.prototype = { // the app let browserLocalAppId = appsService.getAppLocalIdByManifestURL("app://browser.gaiamobile.org/manifest.webapp"); let browserAppStorageDirName = browserLocalAppId + "+f+app+++browser.gaiamobile.org"; - let browserDBFile = FileUtils.getFile("ProfD", - ["storage", - "persistent", - browserAppStorageDirName, - "idb", - browserDBFileName], true); + + // On the phone, the browser db will only be in the old IDB + // directory, since it only existed up until v2.0. On desktop, it + // will exist in the profile directory. + // + // Uses getDir with filename appending to make sure we don't + // create extra directories along the way if they don't already + // exist. + let browserDBFile = FileUtils.getDir(kIDBDirType, + ["storage", + "persistent", + browserAppStorageDirName, + "idb"], false, true); + browserDBFile.append(browserDBFileName); if (!browserDBFile.exists()) { - if (DEBUG) debug("Browser DB file does not exist, nothing to copy"); - return; + if (DEBUG) debug("Browser DB directory " + browserDBFile.path + " does not exist, trying profile location"); + browserDBFile = FileUtils.getDir(kProfileDirType, + ["storage", + "persistent", + browserAppStorageDirName, + "idb"], false, true); + browserDBFile.append(browserDBFileName); + if (!browserDBFile.exists()) { + if (DEBUG) debug("Browser DB directory " + browserDBFile.path + " does not exist. Cannot copy browser db."); + return; + } } let systemLocalAppId = appsService.getAppLocalIdByManifestURL("app://system.gaiamobile.org/manifest.webapp"); let systemAppStorageDirName = systemLocalAppId + "+f+app+++system.gaiamobile.org"; - let systemDBDir = FileUtils.getDir("ProfD", + + // This check futureproofs the system DB storage directory. It + // currently exists outside of the profile but will most likely + // move into the profile at some point. + let systemDBDir = FileUtils.getDir(kIDBDirType, ["storage", "persistent", systemAppStorageDirName, "idb"], false, true); + if (!systemDBDir.exists()) { + if (DEBUG) debug("System DB directory " + systemDBDir.path + " does not exist, trying profile location"); + systemDBDir = FileUtils.getDir(kProfileDirType, + ["storage", + "persistent", + systemAppStorageDirName, + "idb"], false, true); + if (!systemDBDir.exists()) { + if (DEBUG) debug("System DB directory " + systemDBDir.path + " does not exist. Cannot copy browser db."); + return; + } + } + if (DEBUG) { debug("Browser DB file exists, copying"); debug("Browser local id: " + browserLocalAppId + "");