Skip to content

Commit e8229ec

Browse files
committed
fix loading from a symlinked resource path on macOS Catalina and newer [#34]
Fixes #34.
1 parent bb0207b commit e8229ec

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/filesystem.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ bool FS::mkdir(const Path &path)
197197
return true;
198198
}
199199

200+
Path FS::canonical(const Path &path)
201+
{
202+
#ifdef _WIN32
203+
return path;
204+
#else
205+
char *resolved = realpath(path.join().c_str(), nullptr);
206+
Path out(resolved);
207+
free(resolved);
208+
return out;
209+
#endif
210+
}
211+
200212
const char *FS::lastError()
201213
{
202214
return strerror(errno);

src/filesystem.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace FS {
3636
bool mtime(const Path &, time_t *);
3737
bool exists(const Path &, bool dir = false);
3838
bool mkdir(const Path &);
39+
Path canonical(const Path &);
3940

4041
const char *lastError();
4142

src/main.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "api.hpp"
1919
#include "buildinfo.hpp"
2020
#include "errors.hpp"
21+
#include "filesystem.hpp"
2122
#include "menu.hpp"
2223
#include "reapack.hpp"
2324
#include "win32.hpp"
@@ -88,19 +89,22 @@ static void menuHook(const char *name, HMENU handle, const int f)
8889

8990
static bool checkLocation(REAPER_PLUGIN_HINSTANCE module)
9091
{
92+
// using FS::canonical is required on macOS Catalina and newer,
93+
// whose dladdr automatically resolves symbolic links from the module's path
94+
9195
Path expected;
92-
expected.append(ReaPack::resourcePath());
96+
expected.append(FS::canonical(ReaPack::resourcePath()));
9397
expected.append("UserPlugins");
9498
expected.append(REAPACK_FILENAME);
9599

96100
#ifdef _WIN32
97101
Win32::char_type self[MAX_PATH]{};
98102
GetModuleFileName(module, self, static_cast<DWORD>(std::size(self)));
99-
Path current(Win32::narrow(self));
103+
const Path current(Win32::narrow(self));
100104
#else
101105
Dl_info info{};
102106
dladdr(reinterpret_cast<const void *>(&checkLocation), &info);
103-
Path current(info.dli_fname);
107+
const Path &current = FS::canonical({info.dli_fname});
104108
#endif
105109

106110
if(current == expected)

0 commit comments

Comments
 (0)