Bug 1062984 - Make directory service query for bookmark migration more resilient. r=fabrice, a=bajaj
authorKyle Machulis <kyle@nonpolynomial.com>
Thu, 11 Sep 2014 16:57:10 -0700
changeset 217509 ad25b160ac309628624b9951f3e6cd0095752d36
parent 217508 475dda11adedb7a714fde7347684dc324b225dab
child 217510 f88ceebad7f01eb585dc6300e10a90c9b2dbea21
push id6842
push userryanvm@gmail.com
push dateMon, 15 Sep 2014 16:55:09 +0000
treeherdermozilla-aurora@f88ceebad7f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice, bajaj
bugs1062984
milestone34.0a2
Bug 1062984 - Make directory service query for bookmark migration more resilient. r=fabrice, a=bajaj
b2g/components/B2GAppMigrator.js
--- a/b2g/components/B2GAppMigrator.js
+++ b/b2g/components/B2GAppMigrator.js
@@ -10,16 +10,19 @@ function debug(s) {
 const DEBUG = false;
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 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");
 
 XPCOMUtils.defineLazyServiceGetter(this, "appsService",
                                    "@mozilla.org/AppsService;1",
                                    "nsIAppsService");
 
@@ -37,36 +40,70 @@ B2GAppMigrator.prototype = {
     // should be the same on all systems. We should be able to just
     // hardcode it.
     let browserDBFileName = "2959517650brreosw.sqlite";
 
     // Storage directories need to be prefixed with the local id of
     // 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 + "");
       debug("System local id: " + systemLocalAppId + "");
       debug("Browser DB file path: " + browserDBFile.path + "");
       debug("System DB directory path: " + systemDBDir.path + "");
     }