From 3bb9e8c7ebe6e17675fea0d702bf234319af1a9a Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 14 Feb 2020 18:11:32 +0400 Subject: [PATCH] Fix power outage logout only by fsync. --- Telegram/SourceFiles/storage/localstorage.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 7f4d548a53..0ac58bec43 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -269,6 +269,9 @@ struct FileWriteDescriptor { } else { qSwap(toWrite[0], toWrite[1]); } + toDelete = toWrite[1]; + } else if (toWrite1.exists()) { + toDelete = toWrite[1]; } } @@ -332,10 +335,16 @@ struct FileWriteDescriptor { fsync(file.handle()); #endif // Q_OS_WIN file.close(); + + if (!toDelete.isEmpty()) { + QFile::remove(toDelete); + } } QFile file; QDataStream stream; + QString toDelete; + HashMd5 md5; int32 dataSize = 0;