Browse Source

Make settings file recovery more robust

We should not blindly remove the leftover settings file, as the following write()
operation could fail and the user would lost all settings.
We should try renaming it instead.
adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
099314d17f
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 8
      src/base/settingsstorage.cpp

8
src/base/settingsstorage.cpp

@ -241,8 +241,12 @@ QVariantHash TransactionalSettings::read() @@ -241,8 +241,12 @@ QVariantHash TransactionalSettings::read()
.arg(Utils::Fs::toNativePath(newPath))
, Log::WARNING);
Utils::Fs::forceRemove(newPath);
write(res);
QString finalPath = newPath;
int index = finalPath.lastIndexOf("_new", -1, Qt::CaseInsensitive);
finalPath.remove(index, 4);
Utils::Fs::forceRemove(finalPath);
QFile::rename(newPath, finalPath);
}
else {
deserialize(m_name, res);

Loading…
Cancel
Save