From 0c61fb56725a2cc042a03c21c7bee63a16a5e7fe Mon Sep 17 00:00:00 2001 From: Sharaf Zaman Date: Wed, 29 Sep 2021 09:19:54 +0000 Subject: 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. --- src/core/kconfigini.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') 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(); -- cgit v1.2.1