diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-09-15 14:59:07 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-09-22 14:15:19 +0000 |
commit | e9753c6cfd5a0a7fa1c73c19459b815c59a1d6dd (patch) | |
tree | 957700623f4eff2727b51c3aeb4fb0e803f5c84a | |
parent | 116b41eed67ca923ca205d2c7aa0776b0eaa1a4e (diff) | |
download | qtlocation-e9753c6cfd5a0a7fa1c73c19459b815c59a1d6dd.tar.gz |
Check if GenericCacheLocation is writable before trusting it
Enforced application isolation (AppArmor) may make it impossible to write
to $HOME/.cache as applications are only allowed to use their own specific
directories (as returned by CacheLocation). QtCore is not able to recognize
this so the value returned for GenericCacheLocation is still non-empty in
this case. Therefore do a write check.
Task-number: QTBUG-41187
Change-Id: I6ad136abc69997d25715dcdbbc1b8ffb55ec65e0
Reviewed-by: Alberto Mardegan <mardy@users.sourceforge.net>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | src/location/maps/qgeotilecache.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/location/maps/qgeotilecache.cpp b/src/location/maps/qgeotilecache.cpp index 3da2865b..01cfcba4 100644 --- a/src/location/maps/qgeotilecache.cpp +++ b/src/location/maps/qgeotilecache.cpp @@ -468,6 +468,23 @@ QString QGeoTileCache::baseCacheDirectory() // If this is not supported by the platform, use the application-specific cache // location. (e.g. ~/.cache/<app_name>/QtLocation) dir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); + + if (!dir.isEmpty()) { + // The shared cache may not be writable when application isolation is enforced. + static bool writable = false; + static bool writableChecked = false; + if (!writableChecked) { + writableChecked = true; + QDir::root().mkpath(dir); + QFile writeTestFile(QDir(dir).filePath(QStringLiteral("qt_cache_check"))); + writable = writeTestFile.open(QIODevice::WriteOnly); + if (writable) + writeTestFile.remove(); + } + if (!writable) + dir = QString(); + } + if (dir.isEmpty()) dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); |