1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(main): Closing file before removing

Fix #3440
This commit is contained in:
Diadlo 2016-06-26 21:11:19 +03:00
parent 02b6fcb089
commit 29ab61efdf
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727

View File

@ -167,9 +167,13 @@ int main(int argc, char *argv[])
if (QFileInfo(logfile).size() > 1000000)
{
qDebug() << "Log file over 1MB, rotating...";
// close old logfile (need for windows)
if(mainLogFilePtr)
fclose(mainLogFilePtr);
QDir dir (logFileDir);
// Check if log.1 already exists, and if so, delete it
if (dir.remove(logFileDir + "qtox.log.1"))
qDebug() << "Removed old log successfully";
@ -179,10 +183,6 @@ int main(int argc, char *argv[])
if(!dir.rename(logFileDir + "qtox.log", logFileDir + "qtox.log.1"))
qCritical() << "Unable to move logs";
// close old logfile
if(mainLogFilePtr)
fclose(mainLogFilePtr);
// open a new logfile
mainLogFilePtr = fopen(logfile.toLocal8Bit().constData(), "a");
}