Bug 1046924: Move updates directory out of the .app bundle. r=rstrong
authorStephen Pohl <spohl.mozilla.bugs@gmail.com>
Thu, 18 Sep 2014 16:22:36 -0400
changeset 491236 e67519887268a4777071d60e7dbf8f85f828269a
parent 491235 f4e266d5f8f21824c19e9e5d121f41737b73eefe
child 491237 e16f85082398783258c871fe380efb5af8759f53
push id47343
push userbmo:dothayer@mozilla.com
push dateWed, 01 Mar 2017 22:58:58 +0000
reviewersrstrong
bugs1046924
milestone35.0a1
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,46 @@ 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
+  bool hasVendor = gAppData->vendor && strlen(gAppData->vendor) != 0;
+
+  if (hasVendor || gAppData->name) {
+    nsCOMPtr<nsIFile> appRootDirFile;
+    nsCOMPtr<nsIFile> localDir;
+    nsAutoString appDirPath;
 
+    if (NS_SUCCEEDED(appFile->GetParent(getter_AddRefs(appRootDirFile))) &&
+        NS_SUCCEEDED(appRootDirFile->GetPath(appDirPath))) {
+      int32_t dotIndex = appDirPath.RFind(".app");
+      if (dotIndex == kNotFound) {
+        dotIndex = appDirPath.Length();
+      }
+      appDirPath = Substring(appDirPath, 1, dotIndex - 1);
+
+      if (NS_SUCCEEDED(GetUserDataDirectoryHome(getter_AddRefs(localDir),
+                                                true)) &&
+          NS_SUCCEEDED(localDir->AppendNative(nsDependentCString(hasVendor ?
+                                                gAppData->vendor :
+                                                gAppData->name))) &&
+          NS_SUCCEEDED(localDir->Append(NS_LITERAL_STRING("updates"))) &&
+          NS_SUCCEEDED(localDir->AppendRelativePath(appDirPath))) {
+        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 +1144,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)
 {