From 61e68860f83a4c536b00f91fab29c6e3b22ac7fa Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sun, 21 Feb 2016 20:13:53 +0100 Subject: [PATCH] Fix removing of old log files The modification date of the log files was invalid, since QFileInfo was constructed with a filename only and absolute path. Hence no file was ever removed from disk. --- src/blackmisc/filelogger.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/blackmisc/filelogger.cpp b/src/blackmisc/filelogger.cpp index 3dba9ecbe..8780bdaaf 100644 --- a/src/blackmisc/filelogger.cpp +++ b/src/blackmisc/filelogger.cpp @@ -78,11 +78,12 @@ namespace BlackMisc nameFilter += QLatin1String("*.log"); QDir dir(m_logPath, nameFilter, QDir::Name, QDir::Files); - for (const auto &logFile : dir.entryList()) + QDateTime now = QDateTime::currentDateTime(); + for (const auto &logFileInfo : dir.entryInfoList()) { - if (QFileInfo(logFile).lastModified().daysTo(QDateTime::currentDateTime()) > 7 ) + if (logFileInfo.lastModified().daysTo(now) > 7 ) { - dir.remove(logFile); + dir.remove(logFileInfo.fileName()); } } }