Revision: 1035 http://trac.macosforge.org/projects/darwinbuild/changeset/1035 Author: mww@apple.com Date: 2012-05-17 15:56:27 -0700 (Thu, 17 May 2012) Log Message: ----------- More general XPC service cache path. Modified Paths: -------------- branches/PR-11283366/darwinup/Utils.cpp branches/PR-11283366/darwinup/Utils.h branches/PR-11283366/darwinup/main.cpp Modified: branches/PR-11283366/darwinup/Utils.cpp =================================================================== --- branches/PR-11283366/darwinup/Utils.cpp 2012-05-17 22:56:22 UTC (rev 1034) +++ branches/PR-11283366/darwinup/Utils.cpp 2012-05-17 22:56:27 UTC (rev 1035) @@ -371,38 +371,60 @@ res = find_base_system_path(&base, path); if (res) return res; - // xpchelper expects the --root value to *not* end in a slash. - if (has_suffix(base, "/")) { - char *ptr = strrchr(base, '/'); - if (ptr) { - *ptr = '\0'; - } - } - - if (verbosity) { - fprintf(stdout, "Updating xpc services cache for %s ...", base); - fflush(stdout); - } - char* toolpath; join_path(&toolpath, base, "/usr/libexec/xpchelper"); struct stat sb; res = stat(toolpath, &sb); - if (res) { - return 1; - } + if (res || ((sb.st_mode & S_IXUSR) == 0)) { + // no xpchelper + char* cachedir; + join_path(&cachedir, base, "/System/Library/Caches/com.apple.xpcd"); - const char* args[] = { - toolpath, - "--rebuild-cache", - "--root", base, - NULL - }; - res = exec_with_args(args); + res = mkdir_p(cachedir); + if (!res || errno == EEXIST) { + char* cachepath; + join_path(&cachepath, cachedir, "xpcd_cache.dylib"); - if (verbosity) fprintf(stdout, "Done updating xpc cache\n"); + res = open(cachepath, O_APPEND | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (res >= 0) { + close(res); + } else { + fprintf(stderr, "Error: (%d) failed to touch cache file.\n", errno); + res = errno; + } + free(cachepath); + } else { + res = errno; + fprintf(stderr, "Error: (%d) failed to mkdir_p cache directory.\n", res); + } + if (verbosity) fprintf(stdout, "Touched xpc cache file.\n"); + free(cachedir); + } else { + // xpchelper expects the --root value to *not* end in a slash. + if (has_suffix(base, "/")) { + char *ptr = strrchr(base, '/'); + if (ptr) { + *ptr = '\0'; + } + } + if (verbosity) { + fprintf(stdout, "Updating xpc services cache for %s ...", base); + fflush(stdout); + } + + const char* args[] = { + toolpath, + "--rebuild-cache", + "--root", base, + NULL + }; + res = exec_with_args(args); + + if (verbosity) fprintf(stdout, "Done updating xpc cache\n"); + } + free(toolpath); free(base); return res; Modified: branches/PR-11283366/darwinup/Utils.h =================================================================== --- branches/PR-11283366/darwinup/Utils.h 2012-05-17 22:56:22 UTC (rev 1034) +++ branches/PR-11283366/darwinup/Utils.h 2012-05-17 22:56:27 UTC (rev 1035) @@ -41,6 +41,7 @@ #include <stdio.h> #include <assert.h> #include <errno.h> +#include <fcntl.h> #include <libgen.h> #include <limits.h> #include <stdlib.h> Modified: branches/PR-11283366/darwinup/main.cpp =================================================================== --- branches/PR-11283366/darwinup/main.cpp 2012-05-17 22:56:22 UTC (rev 1034) +++ branches/PR-11283366/darwinup/main.cpp 2012-05-17 22:56:27 UTC (rev 1035) @@ -107,8 +107,8 @@ int main(int argc, char* argv[]) { char* progname = strdup(basename(argv[0])); char* path = NULL; -#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 bool disable_automation = false; +#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 bool restart = false; #endif @@ -119,19 +119,15 @@ while ((ch = getopt(argc, argv, "fnp:vh")) != -1) { #endif switch (ch) { -#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 case 'd': disable_automation = true; break; -#endif case 'f': force = 1; break; case 'n': dryrun = 1; -#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 disable_automation = true; -#endif break; case 'p': if (optarg[0] != '/') { @@ -167,8 +163,8 @@ if (dryrun) IF_DEBUG("option: dry run\n"); if (force) IF_DEBUG("option: forcing operations\n"); -#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 if (disable_automation) IF_DEBUG("option: helpful automation disabled\n"); +#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 if (restart) IF_DEBUG("option: restart when finished\n"); #endif @@ -282,13 +278,11 @@ free(sle_path); } #endif -#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 if (!disable_automation && depot->has_modified_xpc_services() && res == 0) { res = update_xpc_services_cache(path); if (res) fprintf(stderr, "Warning: could not update xpc services cache.\n"); res = 0; } -#endif #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 if (restart && res == 0) { res = tell_finder_to_restart();