diff options
author | Masashi Fujimoto <masfj.pub@gmail.com> | 2017-10-05 12:57:05 +0900 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-04-16 06:09:35 +0000 |
commit | edc7aec065356b9f58ce82a038cca092cad76e2d (patch) | |
tree | f837bf4730c393376a1f7832c9f9079cf52222e4 /src | |
parent | 35a36ad478f3bd1cddb9be2ae10f4676302f3460 (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>
(cherry picked from commit aebc9023bb0acb9697540b444a6dfae95b762644)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-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 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<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); |