Index: sources/storage/filehandler.cpp =================================================================== diff -u -rd1907168ef46faa6de1ada400cad789f8379041f -r846a9ebc350e33be4affab3cc4c136248900015d --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision d1907168ef46faa6de1ada400cad789f8379041f) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 846a9ebc350e33be4affab3cc4c136248900015d) @@ -7,7 +7,7 @@ * * \file filehandler.cpp * \author (last) Behrouz NematiPour - * \date (last) 22-Apr-2020 + * \date (last) 25-Aug-2020 * \author (original) Behrouz NematiPour * \date (original) 24-Sep-2019 * @@ -21,6 +21,7 @@ #include #include #include +#include // Project #include "logger.h" @@ -38,9 +39,21 @@ */ void FileHandler::errOut(const QString &vMessage) { - QString mCritical = vMessage; + static uint count; + static QString mCritical; + // coco begin validated : This has been manually test. Needs file system access to produce errors for hundred times. + if (mCritical != vMessage || !(count % 1000)) { + // coco end + count = 0; + mCritical = vMessage; QTextStream err(stderr); - err << mCritical << endl; + err << "FS" << " " + << QDate::currentDate().toString("yyyy_MM_dd") << " " + << QTime::currentTime().toString("HH:mm:ss" ) << " " + << mCritical + << endl; + } + ++count; } /*! @@ -58,11 +71,11 @@ QFile::OpenMode openMode = vAppend ? QFile::Text | QFile::Append : QFile::Text | QFile::WriteOnly; - // coco begin validated : This has been manually test. Needs filesystem access to make file the way it can't be opened for writing. + // coco begin validated : This has been manually test. Needs file system access to make file the way it can't be opened for writing. if (! file.open(openMode)) { QString msg = QString("Can't open file for write (%1).Possible corrupted file system").arg(vFileName); + // here can't use LOG_XXXX because if the folder can't be created then the log can't be written. errOut (msg); - LOG_DEBUG(msg); return false; } // coco end @@ -85,8 +98,8 @@ QFile file(vFileName); if (! file.open(QFile::Text | QFile::ReadOnly)) { QString msg = QString("Can't open file for read (%1).Possible corrupted file system").arg(vFileName); + // here can't use LOG_XXXX because if the folder can't be created then the log can't be written. errOut (msg); - LOG_DEBUG(msg); return false; } QTextStream in(&file); @@ -182,15 +195,15 @@ if (fileTime.date() <= vDateOlderThan) { if (QFile::remove(fileName)) { ++countRemoved; - LOG_DEBUG(QString("%1 File(s) %2 removed").arg(countRemoved).arg(fileName)); + errOut(QString("%1 File(s) %2 removed").arg(countRemoved).arg(fileName)); } else { - LOG_DEBUG(QString("Can't delete file : ") + fileName); + errOut(QString("Can't delete file : ") + fileName); } } } else { - LOG_DEBUG(QString("Can't get last modified date of file : ") + fileName); + errOut(QString("Can't get last modified date of file : ") + fileName); } // coco end } @@ -202,18 +215,47 @@ * \brief FileHandler::makeFolder * \details Create the folder vFolder if it doesn't exist. * \param vFolder - the folder to create - * \return true on successfull creation + * \return true on successful creation */ bool FileHandler::makeFolder(const QString &vFolder) { QDir dir(vFolder); if ( ! dir.exists(vFolder) ) { if ( ! dir.mkpath(vFolder) ) { QString msg = "Can't create folder " + vFolder; - qDebug() << msg; - LOG_DEBUG(msg); + // here can't use LOG_XXXX because if the folder can't be created then the log can't be written. + errOut(msg); return false; } } return true; } + +/*! + * \brief FileHandler::isMounted + * \param vPath - the rootPath of the device mount point + * \return true - if the given vPath is not empty and is in list of mounted devices + * if so it also has to be ready and valid. + */ +bool FileHandler::isMounted(const QString &vPath, bool *vIsReadOnly) +{ + // 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(); + if (path.isEmpty()) return false; + int lastIndex = path.size() - 1; + if (path.at(lastIndex) == "/") path.remove(lastIndex, 1); + // check to see if the path in the list of mounted rootPaths + foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { + if (storage.isValid() && storage.isReady()) { + if ( storage.rootPath() == path ) { + if (vIsReadOnly) *vIsReadOnly = storage.isReadOnly(); + mounted = true; + break; + } + } + } + return mounted; +} +// coco end