Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(671)

Unified Diff: runtime/bin/platform_macos.cc

Issue 1160793004: Resolve the executable path on Mac OS when sym-linked (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/platform_macos.cc
diff --git a/runtime/bin/platform_macos.cc b/runtime/bin/platform_macos.cc
index 702bf017806e811b78243ca729276b7c8cdc8872..d036304d47e2fcd2016c707b7b22e1abfa53b981 100644
--- a/runtime/bin/platform_macos.cc
+++ b/runtime/bin/platform_macos.cc
@@ -7,6 +7,7 @@
#include <mach-o/dyld.h>
+#include "bin/file.h"
#include "bin/platform.h"
#include <crt_externs.h> // NOLINT
@@ -91,6 +92,34 @@ char* Platform::ResolveExecutablePath() {
free(path);
return NULL;
}
+ // If the path is a symbolic link resolve that link.
+ File::Type type = File::GetType(path, false);
+ if (type == File::kIsLink) {
+ char* target_path = File::LinkTarget(path);
+ free(path);
+ return target_path;
+ }
+ // If the directory of the executable is a symbolic link resolve that link.
+ char* last_slash = strrchr(path, '/');
+ if (last_slash != NULL && last_slash != path) {
+ // Split off the last slash and the executable.
+ *last_slash = '\0';
+ File::Type type = File::GetType(path, false);
+ if (type == File::kIsLink) {
+ // Resolve the directory and append the executable.
+ char* target_path = File::LinkTarget(path);
+ *last_slash = '/';
+ size_t new_path_len = strlen(target_path) + strlen(last_slash) + 1;
+ char* new_path = reinterpret_cast<char*>(malloc(new_path_len));
+ snprintf(new_path, new_path_len, "%s%s", target_path, last_slash);
+ free(path);
+ free(target_path);
+ return new_path;
+ } else {
+ // Directory was not a symbolic link re-construct the path.
+ *last_slash = '/';
+ }
kustermann 2015/06/08 08:22:25 So this only handles symlinks to the binary itself
Søren Gjesse 2015/06/09 10:46:48 Thanks Martin. This was a really crappy attempt to
+ }
return path;
}
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698