Make WASM IDB settings use the fallback mechanism correctly
Change-Id: Ibb65efc0faa5ec6e6c60782747c9295e4fc5ff21 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>bb10
parent
8a6a9295eb
commit
0607c25f3e
|
|
@ -243,6 +243,9 @@ public:
|
|||
qsizetype &lineStart, qsizetype &lineLen,
|
||||
qsizetype &equalsPos);
|
||||
|
||||
protected:
|
||||
const QList<QConfFile *> &getConfFiles() const { return confFiles; }
|
||||
|
||||
private:
|
||||
void initFormat();
|
||||
virtual void initAccess();
|
||||
|
|
|
|||
|
|
@ -238,10 +238,11 @@ public:
|
|||
|
||||
void clear() override;
|
||||
void sync() override;
|
||||
void flush() override;
|
||||
|
||||
private:
|
||||
bool writeSettingsToTemporaryFile(const QString &fileName, void *dataPtr, int size);
|
||||
void loadIndexedDBFiles();
|
||||
|
||||
|
||||
QString databaseName;
|
||||
QString id;
|
||||
|
|
@ -264,22 +265,7 @@ QWasmIDBSettingsPrivate::QWasmIDBSettingsPrivate(QSettings::Scope scope,
|
|||
databaseName = organization;
|
||||
id = application;
|
||||
|
||||
int exists = 0;
|
||||
int error = 0;
|
||||
emscripten_idb_exists(DbName, fileName().toLocal8Bit(), &exists, &error);
|
||||
if (error) {
|
||||
setStatus(QSettings::AccessError);
|
||||
return;
|
||||
}
|
||||
if (exists) {
|
||||
void *contents;
|
||||
int size;
|
||||
emscripten_idb_load(DbName, fileName().toLocal8Bit(), &contents, &size, &error);
|
||||
if (error || !writeSettingsToTemporaryFile(fileName(), contents, size)) {
|
||||
setStatus(QSettings::AccessError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
loadIndexedDBFiles();
|
||||
|
||||
QConfFileSettingsPrivate::initAccess();
|
||||
}
|
||||
|
|
@ -288,7 +274,6 @@ QWasmIDBSettingsPrivate::~QWasmIDBSettingsPrivate() = default;
|
|||
|
||||
bool QWasmIDBSettingsPrivate::writeSettingsToTemporaryFile(const QString &fileName, void *dataPtr,
|
||||
int size)
|
||||
|
||||
{
|
||||
QFile file(fileName);
|
||||
QFileInfo fileInfo(fileName);
|
||||
|
|
@ -313,6 +298,10 @@ void QWasmIDBSettingsPrivate::clear()
|
|||
|
||||
void QWasmIDBSettingsPrivate::sync()
|
||||
{
|
||||
// Reload the files, in case there were any changes in IndexedDB, and flush them to disk.
|
||||
// Thanks to this, QConfFileSettingsPrivate::sync will handle key merging correctly.
|
||||
loadIndexedDBFiles();
|
||||
|
||||
QConfFileSettingsPrivate::sync();
|
||||
|
||||
QFile file(fileName());
|
||||
|
|
@ -327,9 +316,26 @@ void QWasmIDBSettingsPrivate::sync()
|
|||
}
|
||||
}
|
||||
|
||||
void QWasmIDBSettingsPrivate::flush()
|
||||
void QWasmIDBSettingsPrivate::loadIndexedDBFiles()
|
||||
{
|
||||
sync();
|
||||
for (const auto *confFile : getConfFiles()) {
|
||||
int exists = 0;
|
||||
int error = 0;
|
||||
emscripten_idb_exists(DbName, confFile->name.toLocal8Bit(), &exists, &error);
|
||||
if (error) {
|
||||
setStatus(QSettings::AccessError);
|
||||
return;
|
||||
}
|
||||
if (exists) {
|
||||
void *contents;
|
||||
int size;
|
||||
emscripten_idb_load(DbName, confFile->name.toLocal8Bit(), &contents, &size, &error);
|
||||
if (error || !writeSettingsToTemporaryFile(confFile->name, contents, size)) {
|
||||
setStatus(QSettings::AccessError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope,
|
||||
|
|
|
|||
|
|
@ -2058,6 +2058,14 @@ void tst_QSettings::testChildKeysAndGroups()
|
|||
l.sort();
|
||||
QCOMPARE(l, QStringList() << "bar" << "foo");
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WASM)
|
||||
// WebIndexedDBFormat does not use the cached settings file on creation, but instead always uses
|
||||
// the file from the indexed DB anew.
|
||||
if (format == QSettings::Format::WebIndexedDBFormat)
|
||||
settings1.sync();
|
||||
#endif
|
||||
|
||||
{
|
||||
QSettings settings3(format, QSettings::UserScope, "software.org", "application");
|
||||
settings3.setFallbacksEnabled(false);
|
||||
|
|
@ -3542,6 +3550,8 @@ void tst_QSettings::rainersSyncBugOnMac()
|
|||
#if defined(Q_OS_WASM)
|
||||
if (format == QSettings::NativeFormat)
|
||||
QSKIP("WASM's localStorage backend recognizes no concept of file");
|
||||
if (format == QSettings::WebIndexedDBFormat)
|
||||
QSKIP("WASM's indexedDB backend uses the virtual FS file only as a backing store");
|
||||
#endif // Q_OS_WASM
|
||||
|
||||
QString fileName;
|
||||
|
|
|
|||
Loading…
Reference in New Issue