Index: sources/storage/FileHandler.cpp =================================================================== diff -u -raf8d98b36b427e2b5f4d6659fcf3b58ee79eab6a -r1f5b2250ae70d305654d014a9aa1fd8baa29779c --- sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision af8d98b36b427e2b5f4d6659fcf3b58ee79eab6a) +++ sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision 1f5b2250ae70d305654d014a9aa1fd8baa29779c) @@ -23,6 +23,7 @@ // Project // #include "Logger.h" // logger should not be used in this class. +#include "StorageGlobals.h" // namespace using namespace Storage; @@ -265,7 +266,6 @@ */ bool FileHandler::isMounted(const QString &vPath, bool *vIsReadOnly) { - // disabled coco begin validated: Needed User Interaction to make the device not ready so tested manually bool mounted = false; // removing the extra '/' from the vPath if there is to be able to compare to the root path of the storage QString path = vPath.trimmed(); @@ -289,9 +289,36 @@ } return mounted; } -// disabled coco end /*! + * \brief FileHandler::tmpUsable + * \details Checks if the temp folder is availabel for read and write to file and directory + * \note This function will only chek the temp folder usability once + * and next call will just return the first result, + * assuming that the temp file situation is not going to change and is stable. + * \return true on success + */ +bool FileHandler::tmpUsable() +{ + static bool ok = false; + static bool tested = false; + if ( tested ) return ok; + + QString tmp = Storage::Standard_tmp; + QString tmpTestFolder = tmp + "tmp_test_folder" ; + QString tmpTestFile = tmp + "tmp_test_file" ; + QString tmpTestContent = "tmp_test_content"; + QDir dir(tmp); + if ( ! dir.exists() ) { ok = false; goto lOut; } + if ( ! FileHandler::makeFolder (tmpTestFolder )) { ok = false; goto lOut; } + if ( ! FileHandler::write (tmpTestFile , tmpTestContent )) { ok = false; goto lOut; } + if ( ! FileHandler::read (tmpTestFolder, tmpTestContent )) { ok = false; goto lOut; } +lOut: + tested = true; + return ok; +} + +/*! * \brief FileHandler::find * \details The function to find files. * It mainly been implemented to find the files are using some amount of total storage in the vPath by percentage, Index: sources/storage/FileHandler.h =================================================================== diff -u -r265600079f9f3b741cd3e67c229f39ec66571419 -r1f5b2250ae70d305654d014a9aa1fd8baa29779c --- sources/storage/FileHandler.h (.../FileHandler.h) (revision 265600079f9f3b741cd3e67c229f39ec66571419) +++ sources/storage/FileHandler.h (.../FileHandler.h) (revision 1f5b2250ae70d305654d014a9aa1fd8baa29779c) @@ -38,7 +38,6 @@ */ class FileHandler { - static void errOut(const QString &vMessage); public: enum FileCopyError_Enums { @@ -58,6 +57,8 @@ }; public: + static void errOut (const QString &vMessage); + static bool write (const QString &vFileName, const QString &vContent, bool vAppend = true ); static bool read (const QString &vFileName, QString &vContent, bool vAppend = false); static bool read (const QString &vFileName, QJsonObject &vContent, QJsonParseError *error = nullptr); @@ -69,6 +70,7 @@ static bool makeFolder (const QString &vFolder); static bool isMounted (const QString &vPath, bool *vIsReadOnly = nullptr); + static bool tmpUsable (); static QFileInfoList find(const QString &vPath, QStringList vNameFilters, quint8 vRetainPercent); static QFileInfoList find(const QString &vPath, QStringList vNameFilters); Index: sources/storage/Logger.cpp =================================================================== diff -u -rf75a5d0d8b5ceb1b9432d0be8a3a20cb81eca5de -r1f5b2250ae70d305654d014a9aa1fd8baa29779c --- sources/storage/Logger.cpp (.../Logger.cpp) (revision f75a5d0d8b5ceb1b9432d0be8a3a20cb81eca5de) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 1f5b2250ae70d305654d014a9aa1fd8baa29779c) @@ -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()); + qDebug() << msg; + FileHandler::errOut(msg); } else { _dir.setPath(SDCard_Base_Path_Name); @@ -243,10 +242,24 @@ 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; } +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; } else { goto lOut; } + if ( ! FileHandler::makeFolder (basePath + Storage::Log_Folder_Treatment )) { basePath = Storage::Standard_tmp; } else { goto lOut; } + if ( ! FileHandler::makeFolder (basePath + Storage::Log_Folder_Pending )) { basePath = Storage::Standard_tmp; } else { goto lOut; } + +lOut: + _logPathNames[vLogType] = basePath + Storage::Log_Folder_Treatment; + emit didLogPathSet(vLogType, _logPathNames[vLogType]); +} + /*! * \brief Logger::setLogPath * \details Sets the log path for the log type vLogType @@ -257,12 +270,11 @@ bool Logger::setLogPath(LogType vLogType) { bool ok = false; - if (vLogType == LogType::eLogTrtmt ) { // treatment logs moved to the encrypted partition/configurations. - _logPathNames[vLogType] = QString("%1/%2").arg(Storage::Settings_Path()).arg(_logBasePathNames[vLogType]); - } - else { - _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; - } + // 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]); return ok; @@ -516,12 +528,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) { Index: sources/storage/Logger.h =================================================================== diff -u -raf8d98b36b427e2b5f4d6659fcf3b58ee79eab6a -r1f5b2250ae70d305654d014a9aa1fd8baa29779c --- sources/storage/Logger.h (.../Logger.h) (revision af8d98b36b427e2b5f4d6659fcf3b58ee79eab6a) +++ sources/storage/Logger.h (.../Logger.h) (revision 1f5b2250ae70d305654d014a9aa1fd8baa29779c) @@ -167,7 +167,7 @@ private: // ----- setting up void checkLogPath (); - void setLogBasePath (bool vUseApplicationDirPath = false); + void setLogBasePath (bool vUseTempPath = false); bool setLogPath (); bool setLogPath (LogType vLogType); public: @@ -195,6 +195,8 @@ private slots: // this slot is thread safe and can be called from outside but preferred not to. bool concurrentRemoveLogs(); void onRemoveLogs(); + void onCryptSetupMount (bool vPass); + signals: /*! * \brief didRemoveLogs Index: sources/storage/Settings.cpp =================================================================== diff -u -r389f028cb9d4d320eae393de7c4408a58a619356 -r1f5b2250ae70d305654d014a9aa1fd8baa29779c --- sources/storage/Settings.cpp (.../Settings.cpp) (revision 389f028cb9d4d320eae393de7c4408a58a619356) +++ sources/storage/Settings.cpp (.../Settings.cpp) (revision 1f5b2250ae70d305654d014a9aa1fd8baa29779c) @@ -217,6 +217,12 @@ return err; } +/*! + * \brief Settings::configurationsMove + * \details After the encrypted partition is ready the configuration files are moved from the root home to denali home. + * \param vMessage + * \return + */ int Settings::configurationsMove(QString *vMessage) { int err = Settings_Error::eError_None ; Index: sources/storage/StorageGlobals.cpp =================================================================== diff -u -r9ef6badf8e172436bba2bfad1642ae7e469e0361 -r1f5b2250ae70d305654d014a9aa1fd8baa29779c --- sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision 9ef6badf8e172436bba2bfad1642ae7e469e0361) +++ sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision 1f5b2250ae70d305654d014a9aa1fd8baa29779c) @@ -33,6 +33,8 @@ /****** TO BE CONSISTENT, ALWAYS INCLUDE '/' AT THE END OF ALL THE FOLDER/DIR/PATH IN HERE ******/ + const char *Standard_tmp = "/tmp/"; + const char *POST_LOG = "post.log"; // this file shall reside in the home folder where the application stored. // USB Index: sources/storage/StorageGlobals.h =================================================================== diff -u -r9ef6badf8e172436bba2bfad1642ae7e469e0361 -r1f5b2250ae70d305654d014a9aa1fd8baa29779c --- sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision 9ef6badf8e172436bba2bfad1642ae7e469e0361) +++ sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision 1f5b2250ae70d305654d014a9aa1fd8baa29779c) @@ -22,6 +22,8 @@ */ namespace Storage { + // standard locations + extern const char *Standard_tmp; // POST extern const char *POST_LOG;