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)
{
logBufferMutex->lock();
if(logBuffer)
{
if (logBuffer)
logBuffer->append(LogMsgBytes);
}
logBufferMutex->unlock();
}
else
{
logBufferMutex->lock();
if(logBuffer)
if (logBuffer)
{
// empty logBuffer to file
foreach(QByteArray msg, *logBuffer)
{
foreach (QByteArray msg, *logBuffer)
fwrite(msg.constData(), 1, msg.size(), logFilePtr);
}
delete logBuffer; // no longer needed
logBuffer = nullptr;
@ -167,27 +164,27 @@ 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";
else
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";
// close old logfile
if(mainLogFilePtr)
fclose(mainLogFilePtr);
// open a new logfile
mainLogFilePtr = fopen(logfile.toLocal8Bit().constData(), "a");
}
if(!mainLogFilePtr)
if (!mainLogFilePtr)
qCritical() << "Couldn't open logfile" << logfile;
logFileFile.store(mainLogFilePtr); // atomically set the logFile
@ -231,19 +228,27 @@ int main(int argc, char *argv[])
autoLogin = true;
}
else
{
profileName = Settings::getInstance().getCurrentProfile();
}
if (parser.positionalArguments().size() == 0)
{
eventType = "activate";
}
else
{
firstParam = parser.positionalArguments()[0];
// 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
if (firstParam.startsWith("tox:"))
{
eventType = "uri";
}
else if (firstParam.endsWith(".tox"))
{
eventType = "save";
}
else
{
qCritical() << "Invalid argument";