diff options
author | Masashi Fujimoto <masfj.pub@gmail.com> | 2017-10-05 12:57:05 +0900 |
---|---|---|
committer | Masashi Fujimoto <masfj.pub@gmail.com> | 2017-10-11 04:51:17 +0000 |
commit | aebc9023bb0acb9697540b444a6dfae95b762644 (patch) | |
tree | 45d7aa3aefcaedd7c8adc8180c39f8606a9d3f83 /src/corelib/io/qstandardpaths_mac.mm | |
parent | 2764d82dc4b2ffdc2a21bd78c75cec14f59c2adf (diff) |
macOS: Fix standardLocations() returns invalid path
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 <AppName>.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 <jake.petroules@qt.io>
Diffstat (limited to 'src/corelib/io/qstandardpaths_mac.mm')
-rw-r--r-- | src/corelib/io/qstandardpaths_mac.mm | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm index e25339a7d1..3bb7a7877a 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<CFURLRef> resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle)) { + if (QCFType<CFURLRef> absoluteResouresURL = CFURLCopyAbsoluteURL(resourcesURL)) { + if (QCFType<CFStringRef> path = CFURLCopyFileSystemPath(absoluteResouresURL, + kCFURLPOSIXPathStyle)) { + dirs.append(QString::fromCFString(path)); + } + } + } } } + const QString localDir = writableLocation(type); if (!localDir.isEmpty()) dirs.prepend(localDir); |