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

Merge pull request #3445

Diadlo (2):
      fix(main): Closing file before removing
      style(main): Small style fixes
This commit is contained in:
sudden6 2016-06-30 13:13:13 +02:00
commit 2c49ada955
No known key found for this signature in database
GPG Key ID: 279509B499E032B9

View File

@ -87,22 +87,19 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QSt
if (!logFilePtr) if (!logFilePtr)
{ {
logBufferMutex->lock(); logBufferMutex->lock();
if(logBuffer) if (logBuffer)
{
logBuffer->append(LogMsgBytes); logBuffer->append(LogMsgBytes);
}
logBufferMutex->unlock(); logBufferMutex->unlock();
} }
else else
{ {
logBufferMutex->lock(); logBufferMutex->lock();
if(logBuffer) if (logBuffer)
{ {
// empty logBuffer to file // empty logBuffer to file
foreach(QByteArray msg, *logBuffer) foreach (QByteArray msg, *logBuffer)
{
fwrite(msg.constData(), 1, msg.size(), logFilePtr); fwrite(msg.constData(), 1, msg.size(), logFilePtr);
}
delete logBuffer; // no longer needed delete logBuffer; // no longer needed
logBuffer = nullptr; logBuffer = nullptr;
@ -167,27 +164,27 @@ int main(int argc, char *argv[])
if (QFileInfo(logfile).size() > 1000000) if (QFileInfo(logfile).size() > 1000000)
{ {
qDebug() << "Log file over 1MB, rotating..."; qDebug() << "Log file over 1MB, rotating...";
// close old logfile (need for windows)
if (mainLogFilePtr)
fclose(mainLogFilePtr);
QDir dir (logFileDir); QDir dir (logFileDir);
// Check if log.1 already exists, and if so, delete it // Check if log.1 already exists, and if so, delete it
if (dir.remove(logFileDir + "qtox.log.1")) if (dir.remove(logFileDir + "qtox.log.1"))
qDebug() << "Removed old log successfully"; qDebug() << "Removed old log successfully";
else else
qWarning() << "Unable to remove old log file"; qWarning() << "Unable to remove old log file";
if(!dir.rename(logFileDir + "qtox.log", logFileDir + "qtox.log.1")) if (!dir.rename(logFileDir + "qtox.log", logFileDir + "qtox.log.1"))
qCritical() << "Unable to move logs"; qCritical() << "Unable to move logs";
// close old logfile
if(mainLogFilePtr)
fclose(mainLogFilePtr);
// open a new logfile // open a new logfile
mainLogFilePtr = fopen(logfile.toLocal8Bit().constData(), "a"); mainLogFilePtr = fopen(logfile.toLocal8Bit().constData(), "a");
} }
if(!mainLogFilePtr) if (!mainLogFilePtr)
qCritical() << "Couldn't open logfile" << logfile; qCritical() << "Couldn't open logfile" << logfile;
logFileFile.store(mainLogFilePtr); // atomically set the logFile logFileFile.store(mainLogFilePtr); // atomically set the logFile
@ -231,19 +228,27 @@ int main(int argc, char *argv[])
autoLogin = true; autoLogin = true;
} }
else else
{
profileName = Settings::getInstance().getCurrentProfile(); profileName = Settings::getInstance().getCurrentProfile();
}
if (parser.positionalArguments().size() == 0) if (parser.positionalArguments().size() == 0)
{
eventType = "activate"; eventType = "activate";
}
else else
{ {
firstParam = parser.positionalArguments()[0]; firstParam = parser.positionalArguments()[0];
// Tox URIs. If there's already another qTox instance running, we ask it to handle the URI and we exit // Tox URIs. If there's already another qTox instance running, we ask it to handle the URI and we exit
// Otherwise we start a new qTox instance and process it ourselves // Otherwise we start a new qTox instance and process it ourselves
if (firstParam.startsWith("tox:")) if (firstParam.startsWith("tox:"))
{
eventType = "uri"; eventType = "uri";
}
else if (firstParam.endsWith(".tox")) else if (firstParam.endsWith(".tox"))
{
eventType = "save"; eventType = "save";
}
else else
{ {
qCritical() << "Invalid argument"; qCritical() << "Invalid argument";