Index: sources/storage/Logger.cpp =================================================================== diff -u -r3d0a160e4e8c0348c688ed5efe4d86dc66121e6b -r5215e145a0f26a20c99e3f10af6ac8a9c3b67383 --- sources/storage/Logger.cpp (.../Logger.cpp) (revision 3d0a160e4e8c0348c688ed5efe4d86dc66121e6b) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 5215e145a0f26a20c99e3f10af6ac8a9c3b67383) @@ -21,6 +21,7 @@ #include #include #include +#include // Project #include "DriveWatcher.h" @@ -204,9 +205,9 @@ { bool ok = true; // coco begin validated: Has been tested manually, this needs user interaction to check the file system - if ( ok && ! setLogPath(LogType::eLogDebug) ) ok = false; if ( ok && ! setLogPath(LogType::eLogEvent) ) ok = false; if ( ok && ! setLogPath(LogType::eLogDatum) ) ok = false; + if ( ok && ! setLogPath(LogType::eLogDebug) ) ok = false; return ok; } // coco end @@ -292,8 +293,9 @@ int result = 0; static QString mOSource; QString mDestination = USB_Mount_Point; - for ( const auto &iType : { eLogEvent , eLogDatum } ) { + for ( const auto &iType : { eLogEvent, eLogDatum } ) { QString mCSource = _logPathNames[iType]; + // if the event and datum are mixed (mOSource == mCSource) in one file then no need to go over the same files in same folder and do it again. if (mOSource != mCSource) { mOSource = mCSource; // Copy Folder @@ -343,29 +345,50 @@ int Logger::removeLogs() { // coco begin validated: This needs user interaction to check the old files deleted + // Storage::FileHandler::find("/media/denali/0CAA-40C1/log/", {"*.err"}, 15); return 0; // has been tested manually + qDebug() << "int Logger::removeLogs()"; static QString mOSource; - int countRemoved = 0; - QStringList mLogFileFilter; - QDate mOlderThan ; + static QString mOExtension; + int removeCount = 0; + QString mLogFileFilter; for ( const auto &iType : { eLogEvent , eLogDatum , eLogDebug } ) { - QString mCSource = _logPathNames[iType]; - if (mOSource != mCSource) { - mOSource = mCSource; + QString mCSource = _logPathNames [iType]; + QString mCExtension = _logFileNameExt[iType]; + // if the event and datum are mixed (mOSource == mCSource && mCExtension == mOExtension) in one file then no need to go over the same files in same folder and do it again. + if (mOSource != mCSource || mCExtension != mOExtension) { + mOSource = mCSource; + mOExtension = mCExtension; // Remove Logs - if (_logTypeExpiryDay.value(iType)) { - mOlderThan = QDate().currentDate().addDays( _logTypeExpiryDay.value(iType) * -1 /*Please Notice (-1)*/ ); - mLogFileFilter = Format::toStringList(_logFileNameExt .values(iType), true, "*"); - LOG_DEBUG(QString("Removing logs older than %1 from folder %2").arg(mOlderThan.toString("yyyy-MM-dd")).arg(mCSource)); - countRemoved += FileHandler::removeFiles({ mCSource }, mLogFileFilter, mOlderThan); + mLogFileFilter = QString("*%1").arg(mCExtension); + /// DEBUG: since it has been manually tested this will help next time for test. + /// qDebug() << "@" << mCSource << mLogFileFilter << mCExtension << iType << _logTypeMaxUsageLimit[iType]; + QFileInfoList fileInfoList = FileHandler::find(mCSource, {mLogFileFilter}, _logTypeMaxUsageLimit[iType]); + removeCount = fileInfoList.count(); + if (removeCount) { + LOG_DEBUG(QString("Removing %1 logs of type (%2) more than %3% limit from folder %4") + .arg(removeCount) + .arg(mCExtension) + .arg(_logTypeMaxUsageLimit[iType]) + .arg(mCSource)); + for (const auto &info: fileInfoList) { + if (info.lastModified().date() == QDate().currentDate()) { + LOG_DEBUG(QString("Current day log %1 cannot be deleted").arg(info.fileName())); + } + else { + /// DEBUG: since it has been manually tested this will help next time for test. + /// qDebug() << "#" << mCSource + info.fileName(); + QFile::remove(info.fileName()); + } + } } else { - LOG_DEBUG("Current day logs cannot be deleted"); + LOG_DEBUG("No log file is deleted for " + mCExtension); } } } mOSource = ""; - return countRemoved; + return removeCount; } // coco end @@ -380,7 +403,8 @@ // coco begin validated: This needs user interaction to check the old files deleted // has been tested manually LOG_DEBUG("Remove Logs Start"); - QFuture mFuture = QtConcurrent::run(this,&Logger::removeLogs); + emit didRemoveLogs(true); + QFuture mFuture = QtConcurrent::run(this, &Logger::removeLogs); _removeLogsWatcher.setFuture(mFuture); return true; } @@ -395,7 +419,7 @@ // coco begin validated: This needs user interaction to export to USB device // has been tested manually LOG_DEBUG(QString("Remove Logs Ended: %1").arg(_removeLogsWatcher.result())); - emit didRemoveLogs(); + emit didRemoveLogs(false); } // coco end