Index: sources/storage/Logger.cpp =================================================================== diff -u -r142f2ddb8ce284c52c0add2acf3ac81f471b78de -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- sources/storage/Logger.cpp (.../Logger.cpp) (revision 142f2ddb8ce284c52c0add2acf3ac81f471b78de) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -1,13 +1,13 @@ /*! * - * Copyright (c) 2020-2022 Diality Inc. - All Rights Reserved. + * Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file Logger.cpp * \author (last) Behrouz NematiPour - * \date (last) 28-Sep-2022 + * \date (last) 15-Oct-2022 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * @@ -146,6 +146,9 @@ this , SLOT( onSDCardStateChange(bool, bool))); connect(&_DeviceController, SIGNAL( didSDCardSpaceChange(bool, qint64, qint64, quint8)), this , SLOT( onSDCardSpaceChange(bool, qint64, qint64, quint8))); + + connect(&_DeviceController, SIGNAL(didCryptSetupMount(bool)), + this , SLOT( onCryptSetupMount(bool))); } /*! @@ -175,14 +178,11 @@ */ void Logger::quitThread() { - // disabled coco begin validated: Application termination is not correctly done in coco!!! - // it has been tested and works perfectly fine in normal run. if (! _thread) return; // runs in thread moveToThread(qApp->thread()); // validated } -// disabled coco end void Logger::onLog(const QString &vContent, LogType vLogType, bool vTimestamp) { @@ -205,11 +205,8 @@ void Logger::checkLogPath() { setLogBasePath(); // try to use /media/sd_card on device - // disabled coco begin validated: It can only happen if the file system is read-only for any reason. - // it has been tested and works perfectly fine in normal run. if (! setLogPath()) { // check and create log folders & if unsuccessful then - // disabled coco end - setLogBasePath(true); // try to use application folder + setLogBasePath(true); // try to use temp folder setLogPath ( ); // check and create log folders // Note: it may require to check for write access regarding device setup } } @@ -219,14 +216,16 @@ * \details Tries to the set the log path to the default log path (Log_Base_Path_Name) * Will set the application folder as the base log path if cannot set the log path to the default. * Will log the event in that case. - * \param vUseApplicationDirPath + * \param vUseTempPath */ -void Logger::setLogBasePath(bool vUseApplicationDirPath) +void Logger::setLogBasePath(bool vUseTempPath) { - if (vUseApplicationDirPath) { - _dir.setPath(qApp->applicationDirPath()); + if (vUseTempPath) { + _dir.setPath(Storage::Standard_tmp); // NOTE: Do not use LOG_XXXXX, At this moment Logger has not been initialized yet - qDebug() << QString("Application path used for events logging (%1)").arg(_dir.path()); + QString msg = QString("temp location used for events logging (%1)").arg(_dir.path()); + //DEBUG qDebug() << msg; + FileHandler::errOut(msg); } else { _dir.setPath(SDCard_Base_Path_Name); @@ -243,11 +242,34 @@ bool ok = true; if ( ok && ! setLogPath(LogType::eLogAppED) ) ok = false; if ( ok && ! setLogPath(LogType::eLogDebug) ) ok = false; - if ( ok && ! setLogPath(LogType::eLogTrtmt) ) ok = false; return ok; } /*! + * \brief Logger::onCryptSetupMount + * \details the handlet for the _DeviceController::didCryptSetupMount + * to set the treatment fodler when the encrypted parttion is ready + * and successfully decrypted and mounted. + * It checks to make sure the folder exist and is able to be written and read. + */ +void Logger::onCryptSetupMount(bool /*vPass*/) +{ + LogType vLogType = LogType::eLogTrtmt; + QString basePath = Storage::Settings_Path(); + + // 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::Log_Folder_Pending )) { basePath = Storage::Standard_tmp; goto lOut; } + +lOut: + _logPathNames[vLogType] = basePath + Storage::Log_Folder_Treatment; + emit didLogPathSet(vLogType, _logPathNames[vLogType]); + + FileHandler::errOut(tr("The '%1' folder selected for the treatment reports").arg(_logPathNames[vLogType])); +} + +/*! * \brief Logger::setLogPath * \details Sets the log path for the log type vLogType * Creates the folder if not exists. @@ -257,6 +279,10 @@ bool Logger::setLogPath(LogType vLogType) { bool ok = false; + // treatment logs moved to the encrypted partition/configurations. + // it handled in onCryptSetupMount + if (vLogType == LogType::eLogTrtmt ) return true; + _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; ok = FileHandler::makeFolder(_logPathNames[vLogType]); if ( ok ) emit didLogPathSet(vLogType, _logPathNames[vLogType]); @@ -511,12 +537,9 @@ */ void Logger::onRemoveLogs() { - // disabled coco begin validated: This needs user interaction to export to USB device - // has been tested manually LOG_DEBUG(tr("Remove Logs Ended: %1").arg(_removeLogsWatcher.result())); emit didRemoveLogs(false); } -// disabled coco end void Logger::onSDCardStateChange(bool vReady, bool vReadonly) {