Bug 436719: Read updater.ini from app dir, not gre. r=bsmedberg, r=robstrong
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 14 Aug 2008 17:08:03 +0100
changeset 16676 e9932544d4f5ad106c124fdb396f957ce1ea8507
parent 16675 53406b58bc1dbc49194c2216ebd0120cd9925939
child 16677 37392cb236bc0a39dca0d5a45a6f4ba3b651a72e
push id1229
push userdtownsend@mozilla.com
push dateThu, 14 Aug 2008 16:10:02 +0000
treeherdermozilla-central@e9932544d4f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, robstrong
bugs436719
milestone1.9.1a2pre
Bug 436719: Read updater.ini from app dir, not gre. r=bsmedberg, r=robstrong
browser/installer/removed-files.in
browser/locales/Makefile.in
toolkit/mozapps/update/src/updater/progressui_osx.mm
toolkit/xre/nsUpdateDriver.cpp
--- a/browser/installer/removed-files.in
+++ b/browser/installer/removed-files.in
@@ -596,16 +596,17 @@ components/nsKillAll.js
 components/passwordmgr.xpt
 components/progressDlg.xpt
 components/safebrowsing.xpt
 components/search.xpt
 components/websrvcs.xpt
 components/widget_mac.xpt
 components/xml-rpc.xpt
 components/xpcom_obsolete.xpt
+updater.app/Contents/MacOS/updater.ini
 init.d/README
 redo-prebinding.sh
 res/viewer.properties
 res/bloatcycle.html
 #endif
 #ifdef XP_UNIX
 #ifndef XP_MACOSX
 readme.txt
--- a/browser/locales/Makefile.in
+++ b/browser/locales/Makefile.in
@@ -304,20 +304,16 @@ endif
 	@$(MAKE) repackage-zip-$*
 
 ifdef MOZ_UPDATER
 libs:: $(addprefix $(LOCALE_SRCDIR)/,updater/updater.ini)
 ifeq ($(OS_ARCH),WINNT)
 	cat $< $(srcdir)/../installer/windows/nsis/updater_append.ini | \
 	  iconv -f UTF-8 -t $(WIN_INSTALLER_CHARSET) > $(FINAL_TARGET)/updater.ini
 else
-ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
-	$(SYSINSTALL) $(IFLAGS1) $^ $(FINAL_TARGET)/updater.app/Contents/MacOS
-else
 	$(SYSINSTALL) $(IFLAGS1) $^ $(FINAL_TARGET)
 endif
 endif
-endif
 
 ifdef MOZ_CRASHREPORTER
 libs:: $(addprefix $(LOCALE_SRCDIR)/,crashreporter/crashreporter-override.ini)
 	$(SYSINSTALL) $(IFLAGS1) $^ $(FINAL_TARGET)
 endif
--- a/toolkit/mozapps/update/src/updater/progressui_osx.mm
+++ b/toolkit/mozapps/update/src/updater/progressui_osx.mm
@@ -44,17 +44,17 @@
 #include "readstrings.h"
 #include "errors.h"
 
 #define TIMER_INTERVAL 0.2
 
 static float sProgressVal;  // between 0 and 100
 static BOOL sQuit = FALSE;
 static StringTable sLabels;
-static const char *sProgramPath;
+static const char *sUpdatePath;
 
 @interface UpdaterUI : NSObject
 {
   IBOutlet NSProgressIndicator *progressBar;
   IBOutlet NSTextField *progressTextField;
 }
 @end
 
@@ -107,34 +107,34 @@ static const char *sProgramPath;
   return sQuit;
 }
 
 @end
 
 int
 InitProgressUI(int *pargc, char ***pargv)
 {
-  sProgramPath = (*pargv)[0];
+  sUpdatePath = (*pargv)[1];
   
   return 0;
 }
 
 int
 ShowProgressUI()
 {
   // Only show the Progress UI if the process is taking significant time.
   // Here we measure significant time as taking more than one second.
   
   usleep(500000);
   
   if (sQuit || sProgressVal > 50.0f)
     return 0;
 
   char path[PATH_MAX];
-  snprintf(path, sizeof(path), "%s.ini", sProgramPath);
+  snprintf(path, sizeof(path), "%s/updater.ini", sUpdatePath);
   if (ReadStrings(path, &sLabels) != OK)
     return -1;
   
   [NSApplication sharedApplication];
   [NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
   [NSApp run];
 
   return 0;
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -270,59 +270,60 @@ SetStatus(nsILocalFile *statusFile, cons
     return PR_FALSE;
 
   fprintf(fp, "%s\n", status);
   fclose(fp);
   return PR_TRUE;
 }
 
 static PRBool
+CopyFileIntoUpdateDir(nsIFile *parentDir, const char *leafName, nsIFile *updateDir)
+{
+  nsDependentCString leaf(leafName);
+  nsCOMPtr<nsIFile> file;
+
+  // Make sure there is not an existing file in the target location.
+  nsresult rv = updateDir->Clone(getter_AddRefs(file));
+  if (NS_FAILED(rv))
+    return PR_FALSE;
+  rv = file->AppendNative(leaf);
+  if (NS_FAILED(rv))
+    return PR_FALSE;
+  file->Remove(PR_FALSE);
+
+  // Now, copy into the target location.
+  rv = parentDir->Clone(getter_AddRefs(file));
+  if (NS_FAILED(rv))
+    return PR_FALSE;
+  rv = file->AppendNative(leaf);
+  if (NS_FAILED(rv))
+    return PR_FALSE;
+  rv = file->CopyToNative(updateDir, EmptyCString());
+  if (NS_FAILED(rv))
+    return PR_FALSE;
+
+  return PR_TRUE;
+}
+
+static PRBool
 CopyUpdaterIntoUpdateDir(nsIFile *greDir, nsIFile *appDir, nsIFile *updateDir,
                          nsCOMPtr<nsIFile> &updater)
 {
-  // We have to move the updater binary and its resource file.
-  const char *filesToMove[] = {
+  // Copy the updater application from the GRE and the updater ini from the app
 #if defined(XP_MACOSX)
-    kUpdaterApp,
+  if (!CopyFileIntoUpdateDir(greDir, kUpdaterApp, updateDir))
+    return PR_FALSE;
 #else
-    kUpdaterINI,
-    kUpdaterBin,
+  if (!CopyFileIntoUpdateDir(greDir, kUpdaterBin, updateDir))
+    return PR_FALSE;
 #endif
-    nsnull
-  };
-
-  nsresult rv;
-
-  for (const char **leafName = filesToMove; *leafName; ++leafName) {
-    nsDependentCString leaf(*leafName);
-    nsCOMPtr<nsIFile> file;
+  CopyFileIntoUpdateDir(appDir, kUpdaterINI, updateDir);
 
-    // Make sure there is not an existing file in the target location.
-    rv = updateDir->Clone(getter_AddRefs(file));
-    if (NS_FAILED(rv))
-      return PR_FALSE;
-    rv = file->AppendNative(leaf);
-    if (NS_FAILED(rv))
-      return PR_FALSE;
-    file->Remove(PR_FALSE);
-
-    // Now, copy into the target location.
-    rv = greDir->Clone(getter_AddRefs(file));
-    if (NS_FAILED(rv))
-      return PR_FALSE;
-    rv = file->AppendNative(leaf);
-    if (NS_FAILED(rv))
-      return PR_FALSE;
-    rv = file->CopyToNative(updateDir, EmptyCString());
-    if (*leafName != kUpdaterINI && NS_FAILED(rv))
-      return PR_FALSE;
-  }
-  
   // Finally, return the location of the updater binary.
-  rv = updateDir->Clone(getter_AddRefs(updater));
+  nsresult rv = updateDir->Clone(getter_AddRefs(updater));
   if (NS_FAILED(rv))
     return PR_FALSE;
 #if defined(XP_MACOSX)
   rv  = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterApp));
   rv |= updater->AppendNative(NS_LITERAL_CSTRING("Contents"));
   rv |= updater->AppendNative(NS_LITERAL_CSTRING("MacOS"));
   if (NS_FAILED(rv))
     return PR_FALSE;