Separate out updater dst from src when copying
☠☠ backed out by 0728e4db897f ☠ ☠
authorBrian R. Bondy <netzen@gmail.com>
Sun, 07 Dec 2014 23:23:25 -0500
changeset 491360 061c798d4c7e5ae5140f9af9cbf7f9980523ef1f
parent 491359 8b75b2e825e80c2e097ab46d5d5e5cbe5036da3f
child 491361 0728e4db897f23e287bf61cb2a69e2c1ca95d45e
push id47343
push userbmo:dothayer@mozilla.com
push dateWed, 01 Mar 2017 22:58:58 +0000
milestone36.0a1
Separate out updater dst from src when copying
toolkit/mozapps/update/tests/unit_aus_update/head_update.js
--- a/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
+++ b/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
@@ -98,17 +98,18 @@ const URL_HOST = "http://localhost";
 
 const FILE_APP_BIN = MOZ_APP_NAME + APP_BIN_SUFFIX;
 const FILE_COMPLETE_EXE = "complete.exe";
 const FILE_HELPER_BIN = "TestAUSHelper" + BIN_SUFFIX;
 const FILE_MAINTENANCE_SERVICE_BIN = "maintenanceservice.exe";
 const FILE_MAINTENANCE_SERVICE_INSTALLER_BIN = "maintenanceservice_installer.exe";
 const FILE_OLD_VERSION_MAR = "old_version.mar";
 const FILE_PARTIAL_EXE = "partial.exe";
-const FILE_UPDATER_BIN = "updater-xpcshell" + BIN_SUFFIX;
+const FILE_UPDATER_BIN = "updater" + BIN_SUFFIX;
+const FILE_UPDATER_SRC_BIN = "updater-xpcshell" + BIN_SUFFIX;
 const FILE_WRONG_CHANNEL_MAR = "wrong_product_channel.mar";
 
 const LOG_SWITCH_SUCCESS = "rename_file: proceeding to rename the directory\n" +
                            "rename_file: proceeding to rename the directory\n" +
                            "Now, remove the tmpDir\n" +
                            "succeeded\n" +
                            "calling QuitProgressUI";
 
@@ -1472,33 +1473,33 @@ if (IS_WIN) {
  *          If null no function will be called when this function finishes.
  *          If not specified the checkUpdateApplied function will be called when
  *          this function finishes.
  */
 function runUpdate(aExpectedExitValue, aExpectedStatus, aCallback) {
   // Copy the updater binary to the updates directory.
   let binDir = gGREBinDirOrig.clone();
   let updater = binDir.clone();
-  updater.append("updater-xpcshell.app");
+  updater.append(FILE_UPDATER_BIN);
   if (!updater.exists()) {
     updater = binDir.clone();
-    updater.append(FILE_UPDATER_BIN);
+    updater.append(FILE_UPDATER_SRC_BIN);
     if (!updater.exists()) {
       do_throw("Unable to find updater binary!");
     }
   }
 
   let updatesDir = getUpdatesPatchDir();
-  updater.copyToFollowingLinks(updatesDir, updater.leafName);
+  updater.copyToFollowingLinks(updatesDir, FILE_UPDATER_BIN);
   let updateBin = updatesDir.clone();
-  updateBin.append(updater.leafName);
-  if (updateBin.leafName == "updater-xpcshell.app") {
+  updateBin.append(FILE_UPDATER_BIN);
+  if (updateBin.leafName == FILE_UPDATER_BIN) {
     updateBin.append("Contents");
     updateBin.append("MacOS");
-    updateBin.append("updater-xpcshell");
+    updateBin.append(FILE_UPDATER_BIN);
     if (!updateBin.exists()) {
       do_throw("Unable to find the updater executable!");
     }
   }
 
   let applyToDir = getApplyDirFile(null, true);
   let applyToDirPath = applyToDir.path;
 
@@ -1776,79 +1777,100 @@ function setupAppFiles() {
     hasMore = istream.readLine(line);
     appFiles.push( { relPath  : line.value,
                      inGreDir : false } );
   } while(hasMore);
 
   istream.close();
 
   appFiles.forEach(function CMAF_FLN_FE(aAppFile) {
-    copyFileToTestAppDir(aAppFile.relPath, aAppFile.inGreDir);
+    let srcPath = aAppFile.relPath;
+    if (aAppFile.relPath === FILE_UPDATER_BIN) {
+        srcPath = FILE_UPDATER_SRC_BIN;
+    }
+    copyFileToTestAppDir(srcPath, aAppFile.relPath, aAppFile.inGreDir);
   });
 
   logTestInfo("finish - copying or creating symlinks to application files " +
               "for the test");
 }
 
 /**
  * Copies the specified files from the dist/bin directory into the test's
  * application directory.
  *
- * @param  aFileRelPath
- *         The relative path to the source and the destination of the file to
- *         copy.
+ * @param  aFileRelSrcPath
+ *         The relative path to the source of the file to copy.
+ * @param  aFileRelDstPath
+ *         The relative path to the destination of the file to copy.
  * @param  aInGreDir
  *         Whether the file is located in the GRE directory which is
  *         <bundle>/Contents/Resources on Mac OS X and is the installation
  *         directory on all other platforms. If false the file must be in the
  *         GRE Binary directory which is <bundle>/Contents/MacOS on Mac OS X and
  *         is the installation directory on on all other platforms.
  */
-function copyFileToTestAppDir(aFileRelPath, aInGreDir) {
+function copyFileToTestAppDir(aFileRelSrcPath, aFileRelDstPath, aInGreDir) {
   // gGREDirOrig and gGREBinDirOrig must always be cloned when changing its
   // properties
   let srcFile = aInGreDir ? gGREDirOrig.clone() : gGREBinDirOrig.clone();
-  let destFile = aInGreDir ? getGREDir() : getGREBinDir();
-  let fileRelPath = aFileRelPath;
-  let pathParts = fileRelPath.split("/");
-  for (let i = 0; i < pathParts.length; i++) {
-    if (pathParts[i]) {
-      srcFile.append(pathParts[i]);
-      destFile.append(pathParts[i]);
+  let fileRelPathSrc = aFileRelSrcPath;
+  let pathPartsSrc = fileRelPathSrc.split("/");
+  for (let i = 0; i < pathPartsSrc.length; i++) {
+    if (pathPartsSrc[i]) {
+      srcFile.append(pathPartsSrc[i]);
     }
   }
 
+  let destFile = aInGreDir ? getGREDir() : getGREBinDir();
+  let fileRelPathDst = aFileRelDstPath;
+  let pathPartsDst = fileRelPathDst.split("/");
+  for (let i = 0; i < pathPartsDst.length; i++) {
+    if (pathPartsDst[i]) {
+      destFile.append(pathPartsDst[i]);
+    }
+  }
+
+
   if (IS_MACOSX && !srcFile.exists()) {
     logTestInfo("unable to copy file since it doesn't exist! Checking if " +
-                 fileRelPath + ".app exists. Path: " +
+                 fileRelPathSrc + ".app exists. Path: " +
                  srcFile.path);
     // gGREDirOrig and gGREBinDirOrig must always be cloned when changing its
     // properties
     srcFile = aInGreDir ? gGREDirOrig.clone() : gGREBinDirOrig.clone();
-    destFile = aInGreDir ? getGREDir() : getGREBinDir();
-    for (let i = 0; i < pathParts.length; i++) {
-      if (pathParts[i]) {
-        srcFile.append(pathParts[i] + (pathParts.length - 1 == i ? ".app" : ""));
-        destFile.append(pathParts[i] + (pathParts.length - 1 == i ? ".app" : ""));
+    for (let i = 0; i < pathPartsSrc.length; i++) {
+      if (pathPartsSrc[i]) {
+        srcFile.append(pathPartsSrc[i] + (pathPartsSrc.length - 1 == i ? ".app" : ""));
       }
     }
-    fileRelPath = fileRelPath + ".app";
+
+    destFile = aInGreDir ? getGREDir() : getGREBinDir();
+    for (let i = 0; i < pathPartsDst.length; i++) {
+      if (pathPartsDst[i]) {
+        destFile.append(pathPartsDst[i] + (pathPartsDst.length - 1 == i ? ".app" : ""));
+      }
+    }
+
+    fileRelPathSrc = fileRelPathSrc + ".app";
+    fileRelPathDst = fileRelPathDst + ".app";
   }
 
   if (!srcFile.exists()) {
     do_throw("Unable to copy file since it doesn't exist! Path: " +
              srcFile.path);
   }
 
   // Symlink libraries. Note that the XUL library on Mac OS X doesn't have a
   // file extension and shouldSymlink will always be false on Windows.
-  let shouldSymlink = (pathParts[pathParts.length - 1] == "XUL" ||
-                       fileRelPath.substr(fileRelPath.length - 3) == ".so" ||
-                       fileRelPath.substr(fileRelPath.length - 6) == ".dylib");
+  let shouldSymlink = (pathPartsSrc[pathPartsSrc.length - 1] == "XUL" ||
+                       fileRelPathSrc.substr(fileRelPathSrc.length - 3) == ".so" ||
+                       fileRelPathSrc.substr(fileRelPathSrc.length - 6) == ".dylib");
   if (!shouldSymlink) {
+
     if (!destFile.exists()) {
       try {
         srcFile.copyToFollowingLinks(destFile.parent, destFile.leafName);
       } catch (e) {
         // Just in case it is partially copied
         if (destFile.exists()) {
           try {
             destFile.remove(true);
@@ -2101,24 +2123,26 @@ function runUpdateUsingService(aInitialS
     gShouldResetEnv = undefined;
   }
 
   setEnvironment();
 
   // There is a security check done by the service to make sure the updater
   // we are executing is the same as the one in the apply-to dir.
   // To make sure they match from tests we copy updater.exe to the apply-to dir.
-  copyFileToTestAppDir(FILE_UPDATER_BIN, false);
+  copyFileToTestAppDir(FILE_UPDATER_SRC_BIN, FILE_UPDATER_BIN, false);
 
   // The service will execute maintenanceservice_installer.exe and
   // will copy maintenanceservice.exe out of the same directory from
   // the installation directory.  So we need to make sure both of those
   // bins always exist in the installation directory.
-  copyFileToTestAppDir(FILE_MAINTENANCE_SERVICE_BIN, false);
-  copyFileToTestAppDir(FILE_MAINTENANCE_SERVICE_INSTALLER_BIN, false);
+  copyFileToTestAppDir(FILE_MAINTENANCE_SERVICE_BIN,
+    FILE_MAINTENANCE_SERVICE_BIN, false);
+  copyFileToTestAppDir(FILE_MAINTENANCE_SERVICE_INSTALLER_BIN,
+    FILE_MAINTENANCE_SERVICE_INSTALLER_BIN, false);
 
   let launchBin = getLaunchBin();
   let args = getProcessArgs(["-dump-args", appArgsLogPath]);
 
   let process = AUS_Cc["@mozilla.org/process/util;1"].
                    createInstance(AUS_Ci.nsIProcess);
   process.init(launchBin);
   logTestInfo("launching " + launchBin.path + " " + args.join(" "));