Index: sources/device/DeviceController.cpp =================================================================== diff -u -rf724589acaa51725f5e5f8a746404d01804efbcf -ra7c8f14c6d5420ea15cdbd8fc6e3c46bae1052cb --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision f724589acaa51725f5e5f8a746404d01804efbcf) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision a7c8f14c6d5420ea15cdbd8fc6e3c46bae1052cb) @@ -27,6 +27,7 @@ #include "Threads.h" #include "StorageGlobals.h" #include "Logger.h" +#include "CloudSyncController.h" #include "ApplicationController.h" #include "FileHandler.h" #include "DeviceModels.h" @@ -119,6 +120,11 @@ connect(&_ApplicationController , SIGNAL(didPOSTCloudSyncData (const QString &)), this , SLOT( onPOSTCloudSyncData (const QString &))); + connect(&_Logger , SIGNAL(didLogBackup (const QString &)), + this , SLOT( onLogBackup (const QString &))); + connect(&_CloudSyncController , SIGNAL(didLogUpload (const QString &)), + this , SLOT( onLogUpload (const QString &))); + DEVICE_DEV_INIT_CONNECTIONS_LIST connect(this, SIGNAL(didEventThreadChange()), @@ -243,6 +249,7 @@ // logs and need a separate disk space usage check settingsPartitionSpaceCheck(); #endif + findPendingLogs(); } /*! @@ -963,6 +970,44 @@ emit didPOSTCloudSyncData (vNetAddress); } +void DeviceController::onLogBackup(const QString &vFileName) +{ + QFileInfo fileInfo(vFileName); + QString filePath(fileInfo.absolutePath()); + QString fileBase(fileInfo.baseName()); + // ------------------------------------------------------------------------ TODO: Improve : get pending type extention + QString fileSufx(fileInfo.completeSuffix().prepend("u.")); + QString fileDest(QString("%1/%2.%3").arg(filePath, fileBase, fileSufx)); + // DEBUG + // qDebug() << ""; + // qDebug() << vFileName; + // qDebug() << fileDest; + QFile::rename(vFileName, fileDest); +} + +void DeviceController::onLogUpload(const QString &vFileName) +{ + QFileInfo fileInfo(vFileName); + QString filePath(Storage::Log_Folder_Base); + QString fileBase(fileInfo.baseName()); + // ------------------------------------------------------------------------ TODO: Improve : get pending type extention + QString fileSufx(fileInfo.completeSuffix().remove("u.")); + // ------------------------------------------------------------------------ TODO: Improve : get type + if( fileSufx == "log" ) { + filePath += Storage::Log_Folder_Application; + } + // ------------------------------------------------------------------------ TODO: Improve : get type + if( fileSufx == "err" ) { + filePath += Storage::Log_Folder_Service; + } + QString fileDest(QString("%1.%2").arg(fileBase, fileSufx)); + // DEBUG + // qDebug() << ""; + // qDebug() << vFileName; + // qDebug() << fileDest; + QFile::rename(filePath + vFileName, filePath + fileDest); +} + /*! * \brief DeviceController::checkConfugurationMountReady * \details Cheks if the system is ready to mount the encrypted partition. @@ -997,6 +1042,54 @@ // and take care of the security flag in the Storage class. } +/*! + * \brief DeviceController::findPendingLogs + * \details this function counts downs for the _pendingInterval + * when the _pendingCounter reaches 0 will search for the files + * and if there is any will get the recent file in the list + */ +void DeviceController::findPendingLogs() +{ + static QString pendingLog = ""; + if( _pendingCounter ) { + _pendingCounter -- ; + return; + } + else { + _pendingCounter = _pendingInterval; // every minute + } + + QFileInfoList pendingFiles; + QString logLoc = Log_Folder_Base; + // ------------------------------------------------------------------------ TODO: Improve : get pending type extention + QString logExt = "*.u.*"; + + for( auto logFolder : { Log_Folder_Application, Log_Folder_Service/*, Log_Folder_CloudSync*/ } ) { + pendingFiles = Storage::FileHandler::find( logLoc + logFolder, { logExt } ); + // look into the list. + // if there are pending files, + // send a request only for the top on the list + /// Note I thought it makes sense to send the oldest on the application and service logs + /// but there some conversation about the situation if something happens on the device, + /// and it would be a critical situation to get the recent/top log and won't wait for the old ones to upload. + // * When gets uploaded, moves from pending then next one comes to top + // the process repeats until there is no file in pending + if ( pendingFiles.count() ) { + // the most recent/first Tx file, to first ask for the current treatment which has just saved as pending on screen + _pendingLog = pendingFiles.first().absoluteFilePath(); + QString message = pendingLog; + LOG_DEBUG(message); + emit didPendingLog( _pendingLog, FileHandler::sha256sum( _pendingLog ) ); + // when a pending file found in the first log folder stop + // until there is none in first one (log) + // then continue to the next log folder (service) ... + goto lOut; + } + } +lOut: + return; +} + ///////////////////////////////////////////// DeviceFactoryReset void DeviceController::onAttributeRequest(const DeviceFactoryResetRequestData &vData) {