commit e8229ec5c8fa9cabe7f517b04bca62765aa4cf0c
parent bb0207bbcbc913b646ada8d7e9497497c9091983
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 15 Mar 2021 12:12:30 -0400
fix loading from a symlinked resource path on macOS Catalina and newer [#34]
Fixes #34.
Diffstat:
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/filesystem.cpp b/src/filesystem.cpp
@@ -197,6 +197,18 @@ bool FS::mkdir(const Path &path)
return true;
}
+Path FS::canonical(const Path &path)
+{
+#ifdef _WIN32
+ return path;
+#else
+ char *resolved = realpath(path.join().c_str(), nullptr);
+ Path out(resolved);
+ free(resolved);
+ return out;
+#endif
+}
+
const char *FS::lastError()
{
return strerror(errno);
diff --git a/src/filesystem.hpp b/src/filesystem.hpp
@@ -36,6 +36,7 @@ namespace FS {
bool mtime(const Path &, time_t *);
bool exists(const Path &, bool dir = false);
bool mkdir(const Path &);
+ Path canonical(const Path &);
const char *lastError();
diff --git a/src/main.cpp b/src/main.cpp
@@ -18,6 +18,7 @@
#include "api.hpp"
#include "buildinfo.hpp"
#include "errors.hpp"
+#include "filesystem.hpp"
#include "menu.hpp"
#include "reapack.hpp"
#include "win32.hpp"
@@ -88,19 +89,22 @@ static void menuHook(const char *name, HMENU handle, const int f)
static bool checkLocation(REAPER_PLUGIN_HINSTANCE module)
{
+ // using FS::canonical is required on macOS Catalina and newer,
+ // whose dladdr automatically resolves symbolic links from the module's path
+
Path expected;
- expected.append(ReaPack::resourcePath());
+ expected.append(FS::canonical(ReaPack::resourcePath()));
expected.append("UserPlugins");
expected.append(REAPACK_FILENAME);
#ifdef _WIN32
Win32::char_type self[MAX_PATH]{};
GetModuleFileName(module, self, static_cast<DWORD>(std::size(self)));
- Path current(Win32::narrow(self));
+ const Path current(Win32::narrow(self));
#else
Dl_info info{};
dladdr(reinterpret_cast<const void *>(&checkLocation), &info);
- Path current(info.dli_fname);
+ const Path ¤t = FS::canonical({info.dli_fname});
#endif
if(current == expected)