From edc7aec065356b9f58ce82a038cca092cad76e2d Mon Sep 17 00:00:00 2001 From: Masashi Fujimoto Date: Thu, 5 Oct 2017 12:57:05 +0900 Subject: macOS: Fix standardLocations() returns invalid path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The file path included in the return value was incorrect when giving the following value to the argument of "QStandardPaths::standardLocations()". - QStandardPaths::AppDataLocation - QStandardPaths::AppLocalDataLocation - QStandardPaths::DataLocation The function to obtain the path to .app changed from CFURLCopyPath() to CFURLCopyFileSystemPath() by commit id c0da37a806dc0457636d787331e9f50778ee8b3e. CFURLCopyPath() returns a value with a path delimiter appended at the end, but CFURLCopyFileSystemPath() is not. This is a commit to append '/' to the end of the return value of CFURLCopyFileSystemPath(). Task-number: QTBUG-61159 Change-Id: Icaebdf09d9cdf992d59c16a398dfe666e6225f99 Reviewed-by: Jake Petroules (cherry picked from commit aebc9023bb0acb9697540b444a6dfae95b762644) Reviewed-by: Tor Arne Vestbø --- src/corelib/io/qstandardpaths_mac.mm | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm index ab73edb008..11b5cc8c37 100644 --- a/src/corelib/io/qstandardpaths_mac.mm +++ b/src/corelib/io/qstandardpaths_mac.mm @@ -203,28 +203,17 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) if (type == AppDataLocation || type == AppLocalDataLocation) { CFBundleRef mainBundle = CFBundleGetMainBundle(); if (mainBundle) { - CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle); - CFStringRef cfBundlePath = CFURLCopyFileSystemPath(bundleUrl, kCFURLPOSIXPathStyle); - QString bundlePath = QString::fromCFString(cfBundlePath); - CFRelease(cfBundlePath); - CFRelease(bundleUrl); - - CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(mainBundle); - CFStringRef cfResourcesPath = CFURLCopyFileSystemPath(resourcesUrl, - kCFURLPOSIXPathStyle); - QString resourcesPath = QString::fromCFString(cfResourcesPath); - CFRelease(cfResourcesPath); - CFRelease(resourcesUrl); - - // Handle bundled vs unbundled executables. CFBundleGetMainBundle() returns - // a valid bundle in both cases. CFBundleCopyResourcesDirectoryURL() returns - // an absolute path for unbundled executables. - if (resourcesPath.startsWith(QLatin1Char('/'))) - dirs.append(resourcesPath); - else - dirs.append(bundlePath + resourcesPath); + if (QCFType resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle)) { + if (QCFType absoluteResouresURL = CFURLCopyAbsoluteURL(resourcesURL)) { + if (QCFType path = CFURLCopyFileSystemPath(absoluteResouresURL, + kCFURLPOSIXPathStyle)) { + dirs.append(QString::fromCFString(path)); + } + } + } } } + const QString localDir = writableLocation(type); if (!localDir.isEmpty()) dirs.prepend(localDir); -- cgit v1.2.3