diff options
author | Sharaf Zaman <shzam@sdf.org> | 2021-09-29 09:19:54 +0000 |
---|---|---|
committer | Sharaf Zaman <shzam@sdf.org> | 2021-09-29 17:43:19 +0000 |
commit | 0c61fb56725a2cc042a03c21c7bee63a16a5e7fe (patch) | |
tree | 39a519cfedafb71173f04cf22209ac3c97de84f4 /src/core/kconfigini.cpp | |
parent | 064f1b11cf93f2b8dad0b0576921da2ff68259ed (diff) | |
download | kconfig-0c61fb56725a2cc042a03c21c7bee63a16a5e7fe.tar.gz kconfig-0c61fb56725a2cc042a03c21c7bee63a16a5e7fe.tar.bz2 |
Android: Fix writing to config if path is a content:// Uri
KConfigIniBackend relies on QLockFile which changes the content Uri and
this is bound to fail because we don't have permission. So, for these
Uris we use Android's Internal cache directory to save the .lock files.
Diffstat (limited to 'src/core/kconfigini.cpp')
-rw-r--r-- | src/core/kconfigini.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp index 0e85cda7..290c3354 100644 --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -505,7 +505,7 @@ bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMa } } else { // Open existing file. *DON'T* create it if it suddenly does not exist! -#ifdef Q_OS_UNIX +#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) int fd = QT_OPEN(QFile::encodeName(filePath()).constData(), O_WRONLY | O_TRUNC); if (fd < 0) { return false; @@ -613,7 +613,20 @@ bool KConfigIniBackend::lock() Q_ASSERT(!filePath().isEmpty()); if (!lockFile) { - lockFile = new QLockFile(filePath() + QLatin1String(".lock")); +#ifdef Q_OS_ANDROID + // handle content Uris properly + if (filePath().startsWith(QLatin1String("content://"))) { + // we can't create file at an arbitrary location, so use internal storage to create one + + // NOTE: filename can be the same, but because this lock is short lived we may never have a collision + lockFile = new QLockFile(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + + QLatin1String("/") + QFileInfo(filePath()).fileName() + QLatin1String(".lock")); + } else { +#endif + lockFile = new QLockFile(filePath() + QLatin1String(".lock")); +#ifdef Q_OS_ANDROID + } +#endif } lockFile->lock(); |