Bug 925747 - patch file extraction cleanup. r=bbondy, a=abillings
authorRobert Strong <robert.bugzilla@gmail.com>
Mon, 27 Jan 2014 10:50:54 -0800
changeset 176037 a994c03f25d40882c1a1852e9e8d781aa346f3c2
parent 176036 27713189accc3ccc485c3d5e5887b0c9745b2ce8
child 176038 9c7bc5a8c72407b059b24a360057f85af5c10442
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)
reviewersbbondy, abillings
bugs925747
milestone28.0a2
Bug 925747 - patch file extraction cleanup. r=bbondy, a=abillings
browser/app/macbuild/Contents/_CodeSignature/CodeResources
toolkit/mozapps/update/tests/unit_aus_update/head_update.js
toolkit/mozapps/update/updater/updater.cpp
--- a/browser/app/macbuild/Contents/_CodeSignature/CodeResources
+++ b/browser/app/macbuild/Contents/_CodeSignature/CodeResources
@@ -49,11 +49,23 @@
                 <real>10</real>
             </dict>
             <key>^MacOS/updates.xml$</key><dict>
                 <key>omit</key>
                 <true/>
                 <key>weight</key>
                 <real>10</real>
             </dict>
+            <key>^Updated.app/.*</key><dict>
+                <key>omit</key>
+                <true/>
+                <key>weight</key>
+                <real>10</real>
+            </dict>
+            <key>^updating/.*</key><dict>
+                <key>omit</key>
+                <true/>
+                <key>weight</key>
+                <real>10</real>
+            </dict>
         </dict>
     </dict>
 </plist>
--- a/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
+++ b/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
@@ -488,16 +488,32 @@ function getUpdatedDirPath() {
   let suffix = "";
   if (gBackgroundUpdate) {
     suffix = UPDATED_DIR_SUFFIX;
   }
   return getApplyDirPath() + suffix;
 }
 
 /**
+ * Helper function for getting the updating directory which is used by the
+ * updater to extract the update manifest and patch files.
+ *
+ * @return  nsIFile for the directory for the updating directory.
+ */
+function getUpdatingDir() {
+  let updatingDir = getApplyDirFile(null, true);
+
+  if (IS_MACOSX) {
+    updatingDir = updatingDir.parent.parent;
+  }
+  updatingDir.append("updating");
+  return updatingDir;
+}
+
+/**
  * Helper function for getting the nsIFile for the directory where the update
  * has been applied.
  *
  * This will be the same as getApplyDirFile for foreground updates, but will
  * point to a different file for the case of background updates.
  *
  * Functions which attempt to access the files in the updated directory should
  * be using this instead of getApplyDirFile.
@@ -700,16 +716,19 @@ function runUpdate() {
 
   // Restore the backed up updater-settings.ini if it exists.
   let updateSettingsIni = getApplyDirFile(null, true);
   updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI_BAK);
   if (updateSettingsIni.exists()) {
     updateSettingsIni.moveTo(updateSettingsIni.parent, FILE_UPDATE_SETTINGS_INI);
   }
 
+  logTestInfo("testing updating directory doesn't exist");
+  do_check_false(getUpdatingDir().exists());
+
   return process.exitValue;
 }
 
 let gServiceLaunchedCallbackLog = null;
 let gServiceLaunchedCallbackArgs = null;
 
 /**
  * Helper function to check whether the maintenance service updater tests should
@@ -1084,16 +1103,20 @@ function runUpdateUsingService(aInitialS
     do_check_eq(status, aExpectedStatus);
 
     timer.cancel();
     timer = null;
 
     if (aCheckSvcLog) {
       checkServiceLogs(svcOriginalLog);
     }
+
+    logTestInfo("testing updating directory doesn't exist");
+    do_check_false(getUpdatingDir().exists());
+
     aCallback();
   }
 
   let timer = AUS_Cc["@mozilla.org/timer;1"].createInstance(AUS_Ci.nsITimer);
   timer.initWithCallback(timerCallback, 1000, timer.TYPE_REPEATING_SLACK);
 }
 
 /**
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -1390,17 +1390,17 @@ int
 PatchFile::Prepare()
 {
   LOG(("PREPARE PATCH " LOG_S, mFile));
 
   // extract the patch to a temporary file
   mPatchIndex = sPatchIndex++;
 
   NS_tsnprintf(spath, sizeof(spath)/sizeof(spath[0]),
-               NS_T("%s/%d.patch"), gSourcePath, mPatchIndex);
+               NS_T("%s/updating/%d.patch"), gDestinationPath, mPatchIndex);
 
   NS_tremove(spath);
 
   FILE *fp = NS_tfopen(spath, NS_T("wb"));
   if (!fp)
     return WRITE_ERROR;
 
 #ifdef XP_WIN
@@ -2227,16 +2227,20 @@ UpdateThreadFunc(void *param)
 
     if (rv == OK && sBackgroundUpdate && !sIsOSUpdate) {
       rv = CopyInstallDirToDestDir();
     }
 
     if (rv == OK) {
       rv = DoUpdate();
       gArchiveReader.Close();
+      NS_tchar updatingDir[MAXPATHLEN];
+      NS_tsnprintf(updatingDir, sizeof(updatingDir)/sizeof(updatingDir[0]),
+                   NS_T("%s/updating"), gDestinationPath);
+      ensure_remove_recursive(updatingDir);
     }
   }
 
   bool reportRealResults = true;
   if (sReplaceRequest && rv && !getenv("MOZ_NO_REPLACE_FALLBACK")) {
     // When attempting to replace the application, we should fall back
     // to non-staged updates in case of a failure.  We do this by
     // setting the status to pending, exiting the updater, and
@@ -3645,29 +3649,31 @@ int AddPreCompleteActions(ActionList *li
 
   return OK;
 }
 
 int DoUpdate()
 {
   NS_tchar manifest[MAXPATHLEN];
   NS_tsnprintf(manifest, sizeof(manifest)/sizeof(manifest[0]),
-               NS_T("%s/update.manifest"), gSourcePath);
+               NS_T("%s/updating/update.manifest"), gDestinationPath);
+  ensure_parent_dir(manifest);
 
   // extract the manifest
   int rv = gArchiveReader.ExtractFile("updatev2.manifest", manifest);
   if (rv) {
     rv = gArchiveReader.ExtractFile("update.manifest", manifest);
     if (rv) {
       LOG(("DoUpdate: error extracting manifest file"));
       return rv;
     }
   }
 
   NS_tchar *rb = GetManifestContents(manifest);
+  NS_tremove(manifest);
   if (rb == nullptr) {
     LOG(("DoUpdate: error opening manifest file: " LOG_S, manifest));
     return READ_ERROR;
   }
 
 
   ActionList list;
   NS_tchar *line;