Chromium Code Reviews| 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; |
| } |