Mac v2 signing - Bug 1046924 - Move updates directory out of the .app bundle. r=rstrong
authorStephen Pohl <spohl.mozilla.bugs@gmail.com>
Mon, 29 Sep 2014 11:51:08 -0700
changeset 207871 0ce9e74b0abe5e7db9d7c31f65a4766db8ee5bff
parent 207870 11d48c719ec9ea3180ac27cb03e9823c3d242c85
child 207872 b503560736fac19cf1b9904674dfab17ba1650aa
push id27569
push usercbook@mozilla.com
push dateTue, 30 Sep 2014 13:14:19 +0000
treeherdermozilla-central@2ae57957e4bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs1046924
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Mac v2 signing - Bug 1046924 - Move updates directory out of the .app bundle. r=rstrong
toolkit/mozapps/update/updater/launchchild_osx.mm
toolkit/xre/nsUpdateDriver.cpp
toolkit/xre/nsXREDirProvider.cpp
--- a/toolkit/mozapps/update/updater/launchchild_osx.mm
+++ b/toolkit/mozapps/update/updater/launchchild_osx.mm
@@ -78,17 +78,17 @@ void
 LaunchMacPostProcess(const char* aAppBundle)
 {
   // Launch helper to perform post processing for the update; this is the Mac
   // analogue of LaunchWinPostProcess (PostUpdateWin).
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
   NSString* iniPath = [NSString stringWithUTF8String:aAppBundle];
   iniPath =
-    [iniPath stringByAppendingPathComponent:@"Contents/MacOS/updater.ini"];
+    [iniPath stringByAppendingPathComponent:@"Contents/Resources/updater.ini"];
 
   NSFileManager* fileManager = [NSFileManager defaultManager];
   if (![fileManager fileExistsAtPath:iniPath]) {
     // the file does not exist; there is nothing to run
     [pool release];
     return;
   }
 
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -336,17 +336,17 @@ CopyFileIntoUpdateDir(nsIFile *parentDir
 }
 
 static bool
 CopyUpdaterIntoUpdateDir(nsIFile *greDir, nsIFile *appDir, nsIFile *updateDir,
                          nsCOMPtr<nsIFile> &updater)
 {
   // Copy the updater application from the GRE and the updater ini from the app
 #if defined(XP_MACOSX)
-  if (!CopyFileIntoUpdateDir(greDir, kUpdaterApp, updateDir))
+  if (!CopyFileIntoUpdateDir(appDir, kUpdaterApp, updateDir))
     return false;
 #else
   if (!CopyFileIntoUpdateDir(greDir, kUpdaterBin, updateDir))
     return false;
 #endif
   CopyFileIntoUpdateDir(appDir, kUpdaterINI, updateDir);
 #if defined(XP_UNIX) && !defined(XP_MACOSX) && !defined(ANDROID)
   nsCOMPtr<nsIFile> iconDir;
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -226,17 +226,17 @@ nsXREDirProvider::GetUserProfilesLocalDi
     }
   }
   file.swap(*aResult);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
-			  nsIFile** aFile)
+                          nsIFile** aFile)
 {
   nsresult rv;
 
   bool gettingProfile = false;
 
   if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR)) {
     // If XRE_NotifyProfile hasn't been called, don't fall through to
     // mAppProvider on the profile keys.
@@ -1026,18 +1026,52 @@ nsXREDirProvider::GetUpdateRootDir(nsIFi
 #else
   nsCOMPtr<nsIFile> appFile;
   bool per = false;
   nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &per, getter_AddRefs(appFile));
   NS_ENSURE_SUCCESS(rv, rv);
   rv = appFile->GetParent(getter_AddRefs(updRoot));
   NS_ENSURE_SUCCESS(rv, rv);
 
-#ifdef XP_WIN
+#ifdef XP_MACOSX
+  nsCOMPtr<nsIFile> appRootDirFile;
+  nsCOMPtr<nsIFile> localDir;
+  nsAutoString appDirPath;
+  if (NS_FAILED(appFile->GetParent(getter_AddRefs(appRootDirFile))) ||
+      NS_FAILED(appRootDirFile->GetPath(appDirPath)) ||
+      NS_FAILED(GetUserDataDirectoryHome(getter_AddRefs(localDir), true))) {
+    return NS_ERROR_FAILURE;
+  }
+
+  int32_t dotIndex = appDirPath.RFind(".app");
+  if (dotIndex == kNotFound) {
+    dotIndex = appDirPath.Length();
+  }
+  appDirPath = Substring(appDirPath, 1, dotIndex - 1);
 
+  bool hasVendor = gAppData->vendor && strlen(gAppData->vendor) != 0;
+  if (hasVendor || gAppData->name) {
+    if (NS_FAILED(localDir->AppendNative(nsDependentCString(hasVendor ?
+                                           gAppData->vendor :
+                                           gAppData->name)))) {
+      return NS_ERROR_FAILURE;
+    }
+  } else if (NS_FAILED(localDir->AppendNative(NS_LITERAL_CSTRING("Mozilla")))) {
+    return NS_ERROR_FAILURE;
+  }
+
+  if (NS_FAILED(localDir->Append(NS_LITERAL_STRING("updates"))) ||
+      NS_FAILED(localDir->AppendRelativePath(appDirPath))) {
+    return NS_ERROR_FAILURE;
+  }
+
+  NS_ADDREF(*aResult = localDir);
+  return NS_OK;
+
+#elif XP_WIN
   nsAutoString pathHash;
   bool pathHashResult = false;
   bool hasVendor = gAppData->vendor && strlen(gAppData->vendor) != 0;
 
   nsAutoString appDirPath;
   if (SUCCEEDED(updRoot->GetPath(appDirPath))) {
 
     // Figure out where we should check for a cached hash value. If the
@@ -1116,17 +1150,17 @@ nsXREDirProvider::GetUpdateRootDir(nsIFi
   }
 
   rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = updRoot->AppendRelativePath(programName);
   NS_ENSURE_SUCCESS(rv, rv);
 
-#endif
+#endif // XP_WIN
 #endif
   NS_ADDREF(*aResult = updRoot);
   return NS_OK;
 }
 
 nsresult
 nsXREDirProvider::GetProfileStartupDir(nsIFile* *aResult)
 {