diff --git a/mac_installer/Installer.cpp b/mac_installer/Installer.cpp index 4fb02ce0eb..061c3adea5 100644 --- a/mac_installer/Installer.cpp +++ b/mac_installer/Installer.cpp @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) { char pkgPath[MAXPATHLEN]; char postInstallAppPath[MAXPATHLEN]; - char temp[MAXPATHLEN]; + char temp[MAXPATHLEN], temp2[MAXPATHLEN]; char brand[64], s[256]; char *p; OSStatus err = noErr; @@ -117,15 +117,35 @@ int main(int argc, char *argv[]) strlcat(postInstallAppPath, "PostInstall.app", sizeof(postInstallAppPath)); p = strrchr(temp, '/'); // Point to name of this application (e.g., "BOINC Installer.app") - if (p == NULL) + if (p == NULL) { p = temp - 1; + } else { + *p = '\0'; + } + + // Delete any old project auto-attach key file from our temp directory + snprintf(temp2, sizeof(temp2), "rm -dfR \"/tmp/%s/%s\"", tempDirName, INSTALLER_FILENAME_FILENAME); + err = callPosixSpawn(temp2); + REPORT_ERROR(err); - // write installer filename to a temp file - // PostInstall.app will copy it into the BOINC Data directory - snprintf(temp, sizeof(temp), "tmp/%s/%s", tempDirName, INSTALLER_FILENAME_FILENAME); - FILE* f = fopen(temp, "w"); - fputs(p+1, f); - fclose(f); + // Write a file containing the project auto-attach key into our temp + // directory because the BOINC Data directory may not yet exist. + // PostInstall.app will copy it into the BOINC Data directory laer + snprintf(temp2, sizeof(temp2), "%s/%s", temp, INSTALLER_FILENAME_FILENAME); + if (boinc_file_exists(temp2)) { + // If the project server put installer_filename.txt file in the same + // parent directory as this installer, copy it into our temp directory + snprintf(temp2, sizeof(temp2), "cp \"%s/%s\" \"/tmp/%s/%s\"", temp, INSTALLER_FILENAME_FILENAME, tempDirName, INSTALLER_FILENAME_FILENAME); + err = callPosixSpawn(temp2); + REPORT_ERROR(err); + } else { + // Create an installer_filename.txt file containing our + // installer's filename and put it in our temp directory + snprintf(temp2, sizeof(temp2), "/tmp/%s/%s", tempDirName, INSTALLER_FILENAME_FILENAME); + FILE* f = fopen(temp2, "w"); + fputs(p+1, f); + fclose(f); + } // To allow for branding, assume name of installer package inside bundle corresponds to name of this application strlcpy(brand, p+1, sizeof(brand));