Index: sources/storage/filehandler.cpp =================================================================== diff -u -rda52c90a17adea2160ac93042e0632a4cda46b1a -r4df19fe88c454bd54abcdaf983be59464c5ef5bc --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision da52c90a17adea2160ac93042e0632a4cda46b1a) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 4df19fe88c454bd54abcdaf983be59464c5ef5bc) @@ -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; - QTextStream err(stderr); - err << mCritical << endl; + 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 << "FS" << " " + << QDate::currentDate().toString("yyyy_MM_dd") << " " + << QTime::currentTime().toString("HH:mm:ss" ) << " " + << mCritical + << endl; + } + ++count; } bool FileHandler::write(const QString &vFileName, const QString &vContent, bool vAppend) @@ -52,8 +65,8 @@ // 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 @@ -75,8 +88,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); @@ -130,15 +143,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 } @@ -159,9 +172,38 @@ if ( ! dir.mkpath(vFolder) ) { QString msg = "Can't create folder " + vFolder; // here can't use LOG_XXXX because if the folder can't be created then the log can't be written. - qDebug() << msg; + 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