From 0ede11a1b7f8e2be5083886fcdadcca83b1d8f82 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 23 Apr 2018 01:53:48 +0800 Subject: [PATCH] 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. --- src/base/settingsstorage.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/base/settingsstorage.cpp b/src/base/settingsstorage.cpp index 99fb6467b..6467d18c8 100644 --- a/src/base/settingsstorage.cpp +++ b/src/base/settingsstorage.cpp @@ -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);