From b3f3fb60999033a7a100102d563e66eaaa876fa3 Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Wed, 20 Oct 2010 21:23:27 +0300 Subject: STORM-417 FIXED Port of SNOW-140 to SG 2.0 : Forced updates not working on Mac The point of this patch is to make the Mac updater code a bit more flexible and reliable than it is right now. The issue is double: * reliability: the string comparison code on the bundle identifier is not UTF8 compliant * flexibility: the bundle identifier is hard coded to match the bundle identifier of LL viewer (i.e. com.secondlife.indra.viewer) so it can't work for another viewer (in particular, it didn't work for Snowglobe). The "bundle identifier" is one of those Mac only thing stored in the Info.plist of a "bundle" (the ".app" folder that's bundling an executable and all its resources and is seen as an application when browsing with the Mac OS X Finder). The patch fixes both issues: * compare correctly UTF8 encoded strings * allow the bundle ID to be passed as a parameter to the updater The patch has really no consequence on LL viewer. It's more a matter of having cleaner, better code. Author: Cypren Christenson Ported and reviewed by: Merov Linden --- indra/mac_updater/mac_updater.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'indra/mac_updater/mac_updater.cpp') diff --git a/indra/mac_updater/mac_updater.cpp b/indra/mac_updater/mac_updater.cpp index e4d100d1ec..23980ffac2 100644 --- a/indra/mac_updater/mac_updater.cpp +++ b/indra/mac_updater/mac_updater.cpp @@ -61,6 +61,7 @@ Boolean gCancelled = false; const char *gUpdateURL; const char *gProductName; +const char *gBundleID; void *updatethreadproc(void*); @@ -329,6 +330,10 @@ int parse_args(int argc, char **argv) { gProductName = argv[j]; } + else if ((!strcmp(argv[j], "-bundleid")) && (++j < argc)) + { + gBundleID = argv[j]; + } } return 0; @@ -355,6 +360,7 @@ int main(int argc, char **argv) // gUpdateURL = NULL; gProductName = NULL; + gBundleID = NULL; parse_args(argc, argv); if (!gUpdateURL) { @@ -372,6 +378,14 @@ int main(int argc, char **argv) { gProductName = "Second Life"; } + if (gBundleID) + { + llinfos << "Bundle ID is: " << gBundleID << llendl; + } + else + { + gBundleID = "com.secondlife.indra.viewer"; + } } llinfos << "Starting " << gProductName << " Updater" << llendl; @@ -592,7 +606,8 @@ static bool isFSRefViewerBundle(FSRef *targetRef) CFURLRef targetURL = NULL; CFBundleRef targetBundle = NULL; CFStringRef targetBundleID = NULL; - + CFStringRef sourceBundleID = NULL; + targetURL = CFURLCreateFromFSRef(NULL, targetRef); if(targetURL == NULL) @@ -619,7 +634,8 @@ static bool isFSRefViewerBundle(FSRef *targetRef) } else { - if(CFStringCompare(targetBundleID, CFSTR("com.secondlife.indra.viewer"), 0) == kCFCompareEqualTo) + sourceBundleID = CFStringCreateWithCString(NULL, gBundleID, kCFStringEncodingUTF8); + if(CFStringCompare(sourceBundleID, targetBundleID, 0) == kCFCompareEqualTo) { // This is the bundle we're looking for. result = true; -- cgit v1.2.3 From 830afa5b27092668517b2f5670e892143de3cf66 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 11 Nov 2010 16:45:38 -0800 Subject: hacking mac updater to install from local dmg --- indra/mac_updater/mac_updater.cpp | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'indra/mac_updater/mac_updater.cpp') diff --git a/indra/mac_updater/mac_updater.cpp b/indra/mac_updater/mac_updater.cpp index 23980ffac2..5f6ea4d33b 100644 --- a/indra/mac_updater/mac_updater.cpp +++ b/indra/mac_updater/mac_updater.cpp @@ -26,6 +26,9 @@ #include "linden_common.h" +#include + +#include #include #include #include @@ -62,6 +65,7 @@ Boolean gCancelled = false; const char *gUpdateURL; const char *gProductName; const char *gBundleID; +const char *gDmgFile; void *updatethreadproc(void*); @@ -334,6 +338,10 @@ int parse_args(int argc, char **argv) { gBundleID = argv[j]; } + else if ((!strcmp(argv[j], "-dmg")) && (++j < argc)) + { + gDmgFile = argv[j]; + } } return 0; @@ -361,10 +369,11 @@ int main(int argc, char **argv) gUpdateURL = NULL; gProductName = NULL; gBundleID = NULL; + gDmgFile = NULL; parse_args(argc, argv); - if (!gUpdateURL) + if ((gUpdateURL == NULL) && (gDmgFile == NULL)) { - llinfos << "Usage: mac_updater -url [-name ] [-program ]" << llendl; + llinfos << "Usage: mac_updater -url | -dmg [-name ] [-program ]" << llendl; exit(1); } else @@ -700,10 +709,14 @@ static OSErr findAppBundleOnDiskImage(FSRef *parent, FSRef *app) // Looks promising. Check to see if it has the right bundle identifier. if(isFSRefViewerBundle(&ref)) { + llinfos << name << " is the one" << llendl; // This is the one. Return it. *app = ref; found = true; + } else { + llinfos << name << " is not the bundle we are looking for; move along" << llendl; } + } } } @@ -921,6 +934,22 @@ void *updatethreadproc(void*) #endif // 0 *HACK for DEV-11935 + // Skip downloading the file if the dmg was passed on the command line. + std::string dmgName; + if(gDmgFile != NULL) { + dmgName = basename((char *)gDmgFile); + char * dmgDir = dirname((char *)gDmgFile); + strncpy(tempDir, dmgDir, sizeof(tempDir)); + err = FSPathMakeRef((UInt8*)tempDir, &tempDirRef, NULL); + if(err != noErr) throw 0; + chdir(tempDir); + goto begin_install; + } else { + // Continue on to download file. + dmgName = "SecondLife.dmg"; + } + + strncat(temp, "/SecondLifeUpdate_XXXXXX", (sizeof(temp) - strlen(temp)) - 1); if(mkdtemp(temp) == NULL) { @@ -979,14 +1008,17 @@ void *updatethreadproc(void*) fclose(downloadFile); downloadFile = NULL; } - + + begin_install: sendProgress(0, 0, CFSTR("Mounting image...")); LLFile::mkdir("mnt", 0700); // NOTE: we could add -private at the end of this command line to keep the image from showing up in the Finder, // but if our cleanup fails, this makes it much harder for the user to unmount the image. std::string mountOutput; - FILE* mounter = popen("hdiutil attach SecondLife.dmg -mountpoint mnt", "r"); /* Flawfinder: ignore */ + boost::format cmdFormat("hdiutil attach %s -mountpoint mnt"); + cmdFormat % dmgName; + FILE* mounter = popen(cmdFormat.str().c_str(), "r"); /* Flawfinder: ignore */ if(mounter == NULL) { @@ -1077,7 +1109,11 @@ void *updatethreadproc(void*) // Move aside old version (into work directory) err = FSMoveObject(&targetRef, &tempDirRef, &asideRef); if(err != noErr) + { + llwarns << "failed to move aside old version (error code " << + err << ")" << llendl; throw 0; + } // Grab the path for later use. err = FSRefMakePath(&asideRef, (UInt8*)aside, sizeof(aside)); @@ -1175,6 +1211,10 @@ void *updatethreadproc(void*) llinfos << "Moving work directory to the trash." << llendl; err = FSMoveObject(&tempDirRef, &trashFolderRef, NULL); + if(err != noErr) { + llwarns << "failed to move files to trash, (error code " << + err << ")" << llendl; + } // snprintf(temp, sizeof(temp), "rm -rf '%s'", tempDir); // printf("%s\n", temp); -- cgit v1.2.3 From ec7d36f6cfbed53a30d918415dfa3e429a645ce1 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 15 Nov 2010 09:38:20 -0800 Subject: added mechanism for install scripts to indicate a failed install and for update service to note the failure; modified mac installer to write marker on error. --- indra/mac_updater/mac_updater.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'indra/mac_updater/mac_updater.cpp') diff --git a/indra/mac_updater/mac_updater.cpp b/indra/mac_updater/mac_updater.cpp index 5f6ea4d33b..5d19e8a889 100644 --- a/indra/mac_updater/mac_updater.cpp +++ b/indra/mac_updater/mac_updater.cpp @@ -66,6 +66,7 @@ const char *gUpdateURL; const char *gProductName; const char *gBundleID; const char *gDmgFile; +const char *gMarkerPath; void *updatethreadproc(void*); @@ -342,6 +343,10 @@ int parse_args(int argc, char **argv) { gDmgFile = argv[j]; } + else if ((!strcmp(argv[j], "-marker")) && (++j < argc)) + { + gMarkerPath = argv[j];; + } } return 0; @@ -370,6 +375,7 @@ int main(int argc, char **argv) gProductName = NULL; gBundleID = NULL; gDmgFile = NULL; + gMarkerPath = NULL; parse_args(argc, argv); if ((gUpdateURL == NULL) && (gDmgFile == NULL)) { @@ -497,11 +503,18 @@ int main(int argc, char **argv) NULL, &retval_mac); } - + + if(gMarkerPath != 0) + { + // Create a install fail marker that can be used by the viewer to + // detect install problems. + std::ofstream stream(gMarkerPath); + if(stream) stream << -1; + } + exit(-1); + } else { + exit(0); } - - // Don't dispose of things, just exit. This keeps the update thread from potentially getting hosed. - exit(0); if(gWindow != NULL) { @@ -713,6 +726,7 @@ static OSErr findAppBundleOnDiskImage(FSRef *parent, FSRef *app) // This is the one. Return it. *app = ref; found = true; + break; } else { llinfos << name << " is not the bundle we are looking for; move along" << llendl; } @@ -721,9 +735,13 @@ static OSErr findAppBundleOnDiskImage(FSRef *parent, FSRef *app) } } } - while(!err && !found); + while(!err); + + llinfos << "closing the iterator" << llendl; FSCloseIterator(iterator); + + llinfos << "closed" << llendl; } if(!err && !found) @@ -1084,12 +1102,19 @@ void *updatethreadproc(void*) throw 0; } + sendProgress(0, 0, CFSTR("Searching for the app bundle...")); err = findAppBundleOnDiskImage(&mountRef, &sourceRef); if(err != noErr) { llinfos << "Couldn't find application bundle on mounted disk image." << llendl; throw 0; } + else + { + llinfos << "found the bundle." << llendl; + } + + sendProgress(0, 0, CFSTR("Preparing to copy files...")); FSRef asideRef; char aside[MAX_PATH]; /* Flawfinder: ignore */ -- cgit v1.2.3