Bug 1053691 - Fallback to /cache if /persist is not available. r=fabrice, a=bajaj
authorKai-Zhen Li <kli@mozilla.com>
Wed, 01 Oct 2014 14:11:44 +0800
changeset 225313 70c0f06356c1725e384423fb0d6f879823a6a06b
parent 225312 f5170efd106107d34889154eb80075a684bfbc37
child 225314 604d60489865476b857e8b9b008472f31224a9b2
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice, bajaj
bugs1053691
milestone34.0a2
Bug 1053691 - Fallback to /cache if /persist is not available. r=fabrice, a=bajaj
b2g/components/ProcessGlobal.js
b2g/components/RecoveryService.js
--- a/b2g/components/ProcessGlobal.js
+++ b/b2g/components/ProcessGlobal.js
@@ -25,17 +25,17 @@ Cu.import('resource://gre/modules/XPCOMU
 function debug(msg) {
   log(msg);
 }
 function log(msg) {
   // This file implements console.log(), so use dump().
   //dump('ProcessGlobal: ' + msg + '\n');
 }
 
-const gFactoryResetFile = "/persist/__post_reset_cmd__";
+const gFactoryResetFile = "__post_reset_cmd__";
 
 function ProcessGlobal() {}
 ProcessGlobal.prototype = {
   classID: Components.ID('{1a94c87a-5ece-4d11-91e1-d29c29f21b28}'),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                          Ci.nsISupportsWeakReference]),
 
   wipeDir: function(path) {
@@ -65,30 +65,38 @@ ProcessGlobal.prototype = {
         this.wipeDir(params[1]);
       }
     });
   },
 
   cleanupAfterFactoryReset: function() {
     log("cleanupAfterWipe start");
 
+    Cu.import("resource://gre/modules/osfile.jsm");
+    let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
+    dir.initWithPath("/persist");
+    var postResetFile = dir.exists() ?
+                        OS.Path.join("/persist", gFactoryResetFile):
+                        OS.Path.join("/cache", gFactoryResetFile);
     let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
-    file.initWithPath(gFactoryResetFile);
+    file.initWithPath(postResetFile);
     if (!file.exists()) {
       debug("Nothing to wipe.")
       return;
     }
 
-    Cu.import("resource://gre/modules/osfile.jsm");
-    let promise = OS.File.read(gFactoryResetFile);
+    let promise = OS.File.read(postResetFile);
     promise.then(
       (array) => {
         file.remove(false);
         let decoder = new TextDecoder();
         this.processWipeFile(decoder.decode(array));
+      },
+      function onError(error) {
+        debug("Error: " + error);
       }
     );
 
     log("cleanupAfterWipe end.");
   },
 
   observe: function pg_observe(subject, topic, data) {
     switch (topic) {
--- a/b2g/components/RecoveryService.js
+++ b/b2g/components/RecoveryService.js
@@ -44,17 +44,17 @@ let librecovery = (function() {
     FotaUpdateStatus:    FotaUpdateStatus,
     getFotaUpdateStatus: library.declare("getFotaUpdateStatus",
                                          ctypes.default_abi,
                                          ctypes.int,
                                          FotaUpdateStatus.ptr)
   };
 })();
 
-const gFactoryResetFile = "/persist/__post_reset_cmd__";
+const gFactoryResetFile = "__post_reset_cmd__";
 
 #endif
 
 function RecoveryService() {}
 
 RecoveryService.prototype = {
   classID: RECOVERYSERVICE_CID,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIRecoveryService]),
@@ -90,22 +90,29 @@ RecoveryService.prototype = {
       for (let i = 0; i < volNames.length; i++) {
         let name = volNames.queryElementAt(i, Ci.nsISupportsString);
         let volume = volumeService.getVolumeByName(name.data);
         log("Got volume: " + name.data + " at " + volume.mountPoint);
         text += "wipe " + volume.mountPoint + "\n";
       }
 
       Cu.import("resource://gre/modules/osfile.jsm");
+      let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
+      dir.initWithPath("/persist");
+      var postResetFile = dir.exists() ?
+                          OS.Path.join("/persist", gFactoryResetFile):
+                          OS.Path.join("/cache", gFactoryResetFile);
       let encoder = new TextEncoder();
       let array = encoder.encode(text);
-      let promise = OS.File.writeAtomic(gFactoryResetFile, array,
-                                        { tmpPath: gFactoryResetFile + ".tmp" });
+      let promise = OS.File.writeAtomic(postResetFile, array,
+                                        { tmpPath: postResetFile + ".tmp" });
 
-      promise.then(doReset);
+      promise.then(doReset, function onError(error) {
+        log("Error: " + error);
+      });
     } else {
       doReset();
     }
 #endif
     throw Cr.NS_ERROR_FAILURE;
   },
 
   installFotaUpdate: function RS_installFotaUpdate(updatePath) {