Bug 757965 - Properly test for write access before staging an update in the background; r=rstrong
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 30 May 2012 17:57:05 -0400
changeset 97730 8818faa56831568017f3c19179cc65dca4daa1da
parent 97729 def37b64a7581fdb3cb5aa5d32d33d73449bc408
child 97731 e3d3a4b05211db1e7dfd7b0a4d7214dc3ff2dfd2
push id1439
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 20:19:22 +0000
treeherdermozilla-aurora@ea74834dccd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs757965
milestone15.0a1
Bug 757965 - Properly test for write access before staging an update in the background; r=rstrong This patch makes sure that we test to make sure we can create a directory in the installation directory and also in its parent (the latter check only happens on Windows and Linux), so that we wouldn't try to stage an update in the background if that's bound to fail if we don't have the require write permissions.
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -427,25 +427,25 @@ XPCOMUtils.defineLazyGetter(this, "gCanS
     // No need to perform directory write checks, the maintenance service will
     // be able to write to all directories.
     LOG("gCanStageUpdates - able to stage updates because we'll use the service");
     return true;
   }
 #endif
 
   try {
-    var updateTestFile = getUpdateFile([FILE_PERMS_TEST]);
+    var updateTestFile = getInstallDirRoot();
+    updateTestFile.append(FILE_PERMS_TEST);
     LOG("gCanStageUpdates - testing write access " + updateTestFile.path);
     testWriteAccess(updateTestFile, true);
 #ifndef XP_MACOSX
     // On all platforms except Mac, we need to test the parent directory as well,
     // as we need to be able to move files in that directory during the replacing
     // step.
-    updateTestFile = getUpdateDirCreate([]);
-    updateTestFile = updateTestFile.parent;
+    updateTestFile = getInstallDirRoot().parent;
     updateTestFile.append(FILE_PERMS_TEST);
     LOG("gCanStageUpdates - testing write access " + updateTestFile.path);
     updateTestFile.createUnique(Ci.nsILocalFile.DIRECTORY_TYPE,
                                 FileUtils.PERMS_DIRECTORY);
     updateTestFile.remove(false);
 #endif
   }
   catch (e) {
@@ -548,16 +548,32 @@ function getUpdateDirCreate(pathArray) {
     return dir;
   } catch (e) {
   }
 #endif
   return FileUtils.getDir(KEY_APPDIR, pathArray, true);
 }
 
 /**
+ * Gets the root of the installation directory which is the application
+ * bundle directory on Mac OS X and the location of the application binary
+ * on all other platforms.
+ *
+ * @return nsIFile object for the directory
+ */
+function getInstallDirRoot() {
+  var dir = FileUtils.getDir(KEY_APPDIR, [], false);
+#ifdef XP_MACOSX
+  // On Mac, we store the Updated.app directory inside the bundle directory.
+  dir = dir.parent.parent;
+#endif
+  return dir;
+}
+
+/**
  * Gets the file at the specified hierarchy under the update root directory.
  * @param   pathArray
  *          An array of path components to locate beneath the directory
  *          specified by |key|. The last item in this array must be the
  *          leaf name of a file.
  * @return  nsIFile object for the file specified. The file is NOT created
  *          if it does not exist, however all required directories along
  *          the way are.