From 5b1cbe8a70774446e07977f699cc1a19376357e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 6 Jun 2021 12:21:41 +0200 Subject: [PATCH] Make sure getSettingsPath() returns the correct directory --- src/main.cpp | 8 +++++++- src/mixxx.cpp | 6 ------ src/util/cmdlineargs.cpp | 2 +- src/util/sandbox.cpp | 4 ++-- src/util/sandbox.h | 2 ++ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 52b2a534a72..416c3490867 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,8 +84,14 @@ int main(int argc, char * argv[]) { // the main thread. Bug #1748636. ErrorDialogHandler::instance(); - MixxxApplication app(argc, argv); +#ifdef __APPLE__ + Sandbox::checkSandboxed(); + if (!args.getSettingsPathSet()) { + args.setSettingsPath(Sandbox::migrateOldSettings()); + } +#endif + MixxxApplication app(argc, argv); #ifdef __APPLE__ QDir dir(QApplication::applicationDirPath()); diff --git a/src/mixxx.cpp b/src/mixxx.cpp index 3d38eb1358e..dbd22990496 100644 --- a/src/mixxx.cpp +++ b/src/mixxx.cpp @@ -172,12 +172,6 @@ MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args) mixxx::Time::start(); QString settingsPath = args.getSettingsPath(); -#ifdef __APPLE__ - Sandbox::checkSandboxed(); - if (!args.getSettingsPathSet()) { - settingsPath = Sandbox::migrateOldSettings(); - } -#endif mixxx::LogFlags logFlags = mixxx::LogFlag::LogToFile; if (args.getDebugAssertBreak()) { diff --git a/src/util/cmdlineargs.cpp b/src/util/cmdlineargs.cpp index 90cad012684..36ecb2f0185 100644 --- a/src/util/cmdlineargs.cpp +++ b/src/util/cmdlineargs.cpp @@ -55,7 +55,7 @@ bool CmdlineArgs::Parse(int &argc, char **argv) { if (!m_settingsPath.endsWith("/")) { m_settingsPath.append("/"); } - m_settingsPathSet=true; + m_settingsPathSet = true; } else if (argv[i] == QString("--resourcePath") && i+1 < argc) { m_resourcePath = QString::fromLocal8Bit(argv[i+1]); i++; diff --git a/src/util/sandbox.cpp b/src/util/sandbox.cpp index 2da61d8fe40..de7bbc0a772 100644 --- a/src/util/sandbox.cpp +++ b/src/util/sandbox.cpp @@ -366,6 +366,7 @@ SecurityTokenPointer Sandbox::openTokenFromBookmark(const QString& canonicalPath return SecurityTokenPointer(); } +#ifdef __APPLE__ QString Sandbox::migrateOldSettings() { // QStandardPaths::DataLocation returns a different location depending on whether the build // is signed (and therefore sandboxed with the hardened runtime), so use the absolute path @@ -438,7 +439,6 @@ QString Sandbox::migrateOldSettings() { return sandboxedPath; } -#ifdef __APPLE__ CFURLRef url = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, QStringToCFString(legacySettingsPath), kCFURLPOSIXPathStyle, true); if (url) { @@ -498,9 +498,9 @@ QString Sandbox::migrateOldSettings() { } } } -#endif return sandboxedPath; } +#endif #ifdef __APPLE__ SandboxSecurityToken::SandboxSecurityToken(const QString& path, CFURLRef url) diff --git a/src/util/sandbox.h b/src/util/sandbox.h index d48f093df24..31ca9f34cc7 100644 --- a/src/util/sandbox.h +++ b/src/util/sandbox.h @@ -32,7 +32,9 @@ class Sandbox { static void setPermissionsFilePath(const QString& permissionsFile); static void shutdown(); +#ifdef __APPLE__ static QString migrateOldSettings(); +#endif // Returns true if we are in a sandbox. static bool enabled() {