Index: sources/storage/Logger.cpp =================================================================== diff -u -r75e10e5c2ada62906baded5ba8731977e51b1357 -r5bb4a64727ce89d613ab0b79813b1a3f768291ff --- sources/storage/Logger.cpp (.../Logger.cpp) (revision 75e10e5c2ada62906baded5ba8731977e51b1357) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 5bb4a64727ce89d613ab0b79813b1a3f768291ff) @@ -260,8 +260,8 @@ /*! * \brief Logger::onCryptSetupMount - * \details the handlet for the _DeviceController::didCryptSetupMount - * to set the treatment fodler when the encrypted parttion is ready + * \details the handler for the _DeviceController::didCryptSetupMount + * to set the treatment folder when the encrypted partition is ready * and successfully decrypted and mounted. * It checks to make sure the folder exist and is able to be written and read. */ @@ -272,10 +272,10 @@ // use the Settings path first (/var/configurations (Encrypted Partition)) if ( ! QDir (basePath ).exists( )) { basePath = Storage::Standard_tmp; goto lOut; } - if ( ! FileHandler::makeFolder (basePath + Storage::Log_Folder_Treatment )) { basePath = Storage::Standard_tmp; goto lOut; } + if ( ! FileHandler::makeFolder (basePath + Storage::Txr_Folder_Treatment )) { basePath = Storage::Standard_tmp; goto lOut; } lOut: - _logPathNames[vLogType] = basePath + Storage::Log_Folder_Treatment; + _logPathNames[vLogType] = basePath + Storage::Txr_Folder_Treatment; emit didLogPathSet(vLogType, _logPathNames[vLogType]); FileHandler::errOut(tr("The '%1' folder selected for the treatment reports").arg(_logPathNames[vLogType])); @@ -491,44 +491,49 @@ * \details Remove old logs by iterating in the log/service folders and look for expired logs. * \return count file(s) have been removed. */ -int Logger::removeLogs() +int Logger::removeLogs(LogType vLogType) { // Storage::FileHandler::find("/media/denali/0CAA-40C1/log/", {"*.err"}, 15); return 0; // has been tested manually LOG_DEBUG(tr("Initializing log clean up")); int removeCount = 0; - for ( const auto &iType : { eLogAppED , eLogDebug , eLogTrtmt } ) { + auto logFiles = { eLogAppED , eLogDebug , eLogCloud }; // TODO: UI (Linux denali user has no access to the CloudSync log folders to delete) + auto logFile = { vLogType }; // Is mostly used for the txr files which are in separate partition. + + for ( const auto &iType : ( vLogType == eLogFiles ? logFiles : logFile ) ) { QString mCSource = _logPathNames [iType]; QString mCExtension = _logFileNameExt[iType]; // DEBUG: qDebug() << "@" << mCSource << mLogFileFilter << mCExtension << iType << _logTypeMaxUsageLimit[iType]; - QFileInfoList fileInfoList = FileHandler::find(mCSource, {"*.*"}, _logTypeMaxUsageLimit[iType]); + QFileInfoList fileInfoList = FileHandler::find( + mCSource , // where to look + {"*.*"} , // what to delete // it means the removal will be for all the files in that location and won't look at the mCExtension + _logTypeMaxUsageLimit[iType]); // how many/much removeCount = fileInfoList.count(); // qDebug() << "@" << removeCount << fileInfoList; - 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 { - QString mFileName = mCSource + info.fileName(); - // DEBUG: qDebug() << "#" << mFileName; - bool ok = QFile::remove(mFileName); - if (ok) { - LOG_DEBUG(QString("Removing %1 succeeded").arg(mFileName)); - } else { - LOG_DEBUG(QString("Removing %1 failed" ).arg(mFileName)); - } - } + if ( ! removeCount ) { LOG_DEBUG(QString("No log file to delete for type(%1) more than %2% limit from folder %3") + .arg(mCExtension) + .arg(_logTypeMaxUsageLimit[iType]) + .arg(mCSource)); continue; } + 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) { + bool isWritable = info.isWritable(); + bool isOldLog = info.lastModified().date() != QDate().currentDate(); + if ( ! isWritable ) { LOG_DEBUG(QString("Log %1 cannot be deleted" ).arg(info.fileName())); continue; } + if ( ! isOldLog ) { LOG_DEBUG(QString("Current day log %1 cannot be deleted" ).arg(info.fileName())); continue; } + + QString mFileName = mCSource + info.fileName(); + // DEBUG: qDebug() << "#" << mFileName; + bool ok = QFile::remove(mFileName); + if (ok) { + LOG_DEBUG(QString("Removing %1 succeeded").arg(mFileName)); + } else { + LOG_DEBUG(QString("Removing %1 failed" ).arg(mFileName)); } } - else { - LOG_DEBUG("No log file is deleted for " + mCExtension); - } } return removeCount; } @@ -539,13 +544,13 @@ * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentRemoveLogs() +bool Logger::concurrentRemoveLogs(LogType vLogType) { // disabled coco begin validated: This needs user interaction to check the old files deleted // has been tested manually LOG_DEBUG("Remove Logs Starting"); emit didRemoveLogs(true); - QFuture mFuture = QtConcurrent::run(this, &Logger::removeLogs); + QFuture mFuture = QtConcurrent::run(this, &Logger::removeLogs, vLogType); _removeLogsWatcher.setFuture(mFuture); return true; } @@ -631,8 +636,8 @@ if ( ! vReady ) return; // DEBUG: qDebug() << vPercent << Storage::Available_Space_Percent; - if ( Storage::Log_Min_Available_Total_Space_IsLow(vPercent) ) { - concurrentRemoveLogs(); + if ( Storage::Txr_Min_Available_Total_Space_IsLow(vPercent) ) { + concurrentRemoveLogs(eLogTrtmt); } } // disabled coco end