Bug 931740 - Check the available free space for update. r=dhylands, a=1.3+
authorKai-Zhen Li <kli@mozilla.com>
Tue, 17 Dec 2013 11:24:14 +0800
changeset 175714 8911ddbd3ab7b742bf97bf234f7c4bb08c2d144e
parent 175713 d828e088eafb5742a566a0cfa418a84bc81af5ff
child 175715 2e8a7007ceec1ae3ab5c5de3f41b324890e2d300
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands, 1
bugs931740
milestone28.0a2
Bug 931740 - Check the available free space for update. r=dhylands, a=1.3+
b2g/components/DirectoryProvider.js
--- a/b2g/components/DirectoryProvider.js
+++ b/b2g/components/DirectoryProvider.js
@@ -81,23 +81,25 @@ DirectoryProvider.prototype = {
       file.initWithPath("/system/b2g");
       persistent.value = true;
       return file;
     }
     if (prop == UPDATE_ARCHIVE_DIR) {
       // getUpdateDir will set persistent to false since it may toggle between
       // /data/local/ and /mnt/sdcard based on free space and/or availability
       // of the sdcard.
-      return this.getUpdateDir(persistent, UPDATES_DIR);
+      // before download, check if free space is 2.1 times of update.mar
+      return this.getUpdateDir(persistent, UPDATES_DIR, 2.1);
     }
     if (prop == XRE_OS_UPDATE_APPLY_TO_DIR) {
       // getUpdateDir will set persistent to false since it may toggle between
       // /data/local/ and /mnt/sdcard based on free space and/or availability
       // of the sdcard.
-      return this.getUpdateDir(persistent, FOTA_DIR);
+      // before apply, check if free space is 1.1 times of update.mar
+      return this.getUpdateDir(persistent, FOTA_DIR, 1.1);
     }
 #else
     // In desktop builds, coreAppsDir is the same as the profile directory.
     // We just need to get the path from the parent, and it is then used to
     // build jar:remoteopenfile:// uris.
     if (prop == "coreAppsDir") {
       let appsDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
       appsDir.append("webapps");
@@ -166,17 +168,17 @@ DirectoryProvider.prototype = {
       }
       log("Warning: " + LOCAL_DIR + " has enough free space for update " +
           activeUpdate.name + ", but is not writable");
     }
 
     return null;
   },
 
-  getUpdateDir: function dp_getUpdateDir(persistent, subdir) {
+  getUpdateDir: function dp_getUpdateDir(persistent, subdir, multiple) {
     let defaultUpdateDir = this.getDefaultUpdateDir();
     persistent.value = false;
 
     let activeUpdate = Services.um.activeUpdate;
     if (!activeUpdate) {
       log("Warning: No active update found, using default update dir: " +
           defaultUpdateDir);
       return defaultUpdateDir;
@@ -184,17 +186,17 @@ DirectoryProvider.prototype = {
 
     let selectedPatch = activeUpdate.selectedPatch;
     if (!selectedPatch) {
       log("Warning: No selected patch, using default update dir: " +
           defaultUpdateDir);
       return defaultUpdateDir;
     }
 
-    let requiredSpace = selectedPatch.size * 2;
+    let requiredSpace = selectedPatch.size * multiple;
     let updateDir = this.findUpdateDirWithFreeSpace(requiredSpace, subdir);
     if (updateDir) {
       return updateDir;
     }
 
     // If we've gotten this far, there isn't enough free space to download the patch
     // on either external storage or /data/local. All we can do is report the
     // error and let upstream code handle it more gracefully.