Bug 1077715 - Copy sqlite directory when doing b2g browser migration; r=fabrice
authorKyle Machulis <kyle@nonpolynomial.com>
Thu, 15 Jan 2015 14:39:51 -0800
changeset 224180 0630fff937bbffb54dddb229ee9a7610569721a5
parent 224106 ed23181e27f9e436a1f3c1490f7888252c2225ed
child 224181 e37e5a3677b94a83cf8eaa67448ead39d96b3395
push id54150
push usercbook@mozilla.com
push dateFri, 16 Jan 2015 14:14:56 +0000
treeherdermozilla-inbound@ac6623427298 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1077715
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1077715 - Copy sqlite directory when doing b2g browser migration; r=fabrice
b2g/components/B2GAppMigrator.js
--- a/b2g/components/B2GAppMigrator.js
+++ b/b2g/components/B2GAppMigrator.js
@@ -29,20 +29,22 @@ XPCOMUtils.defineLazyServiceGetter(this,
 function B2GAppMigrator() {
 }
 
 B2GAppMigrator.prototype = {
   classID:         Components.ID('{7211ece0-b458-4635-9afc-f8d7f376ee95}'),
   QueryInterface:  XPCOMUtils.generateQI([Ci.nsIObserver,
                                           Ci.nsISupportsWeakReference]),
   executeBrowserMigration: function() {
-    // The browser db name is hashed the same way everywhere, so it
-    // should be the same on all systems. We should be able to just
-    // hardcode it.
-    let browserDBFileName = "2959517650brreosw.sqlite";
+    if (DEBUG) debug("Executing Browser Migration");
+    // The browser db file and directory names are hashed the same way
+    // everywhere, so it should be the same on all systems. We should
+    // be able to just hardcode it.
+    let browserDBDirName = "2959517650brreosw";
+    let browserDBFileName = browserDBDirName + ".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";
 
     // 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
@@ -52,29 +54,45 @@ B2GAppMigrator.prototype = {
     // 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);
+    let browserDBDir = FileUtils.getDir(kIDBDirType,
+                                        ["storage",
+                                         "persistent",
+                                         browserAppStorageDirName,
+                                         "idb",
+                                         browserDBDirName
+                                        ], false, true);
 
     if (!browserDBFile.exists()) {
-      if (DEBUG) debug("Browser DB directory " + browserDBFile.path + " does not exist, trying profile location");
+      if (DEBUG) debug("Browser DB " + 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.");
+        if (DEBUG) debug("Browser DB " + browserDBFile.path + " does not exist. Cannot copy browser db.");
         return;
       }
+      // If we have confirmed we have a DB file, we should also have a
+      // directory.
+      browserDBDir = FileUtils.getDir(kProfileDirType,
+                                      ["storage",
+                                       "persistent",
+                                       browserAppStorageDirName,
+                                       "idb",
+                                       browserDBDirName
+                                      ], false, true);
     }
 
     let systemLocalAppId = appsService.getAppLocalIdByManifestURL("app://system.gaiamobile.org/manifest.webapp");
     let systemAppStorageDirName = systemLocalAppId + "+f+app+++system.gaiamobile.org";
 
     // 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.
@@ -97,24 +115,30 @@ B2GAppMigrator.prototype = {
       }
     }
 
     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("Browser DB dir path: " + browserDBDir.path + "");
       debug("System DB directory path: " + systemDBDir.path + "");
     }
 
     try {
       browserDBFile.copyTo(systemDBDir, browserDBFileName);
     } catch (e) {
       debug("File copy caused error! " + e.name);
     }
+    try {
+      browserDBDir.copyTo(systemDBDir, browserDBDirName);
+    } catch (e) {
+      debug("Dir copy caused error! " + e.name);
+    }
     if (DEBUG) debug("Browser DB copied successfully");
   },
 
   observe: function(subject, topic, data) {
     switch (topic) {
       case kMigrationMessageName:
         this.executeBrowserMigration();
         break;