Index: sources/storage/FileHandler.cpp =================================================================== diff -u -r142f2ddb8ce284c52c0add2acf3ac81f471b78de -rcf51c19d82d667644d7f70eaa521b43f908c7068 --- sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision 142f2ddb8ce284c52c0add2acf3ac81f471b78de) +++ sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision cf51c19d82d667644d7f70eaa521b43f908c7068) @@ -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 FileHandler.cpp * \author (last) Behrouz NematiPour - * \date (last) 27-Jun-2022 + * \date (last) 22-Jan-2023 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * @@ -23,6 +23,7 @@ // Project // #include "Logger.h" // logger should not be used in this class. +#include "StorageGlobals.h" // namespace using namespace Storage; @@ -49,7 +50,7 @@ << QDate::currentDate().toString("yyyy_MM_dd") << " " << QTime::currentTime().toString("HH:mm:ss" ) << " " << mCritical - << endl; + << Qt::endl; } ++count; } @@ -90,7 +91,7 @@ * \param vContent - The content of the file which will be set when done. * \return false if file cannot be opened. */ -bool FileHandler::read(const QString &vFileName, QString &vContent) +bool FileHandler::read(const QString &vFileName, QString &vContent, bool vAppend) { QFile file(vFileName); if (! file.open(QFile::Text | QFile::ReadOnly)) { @@ -100,7 +101,12 @@ return false; } QTextStream in(&file); - vContent = in.readAll(); + if ( vAppend ) { + vContent += in.readAll(); + } + else { + vContent = in.readAll(); + } return true; } @@ -260,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(); @@ -284,9 +289,36 @@ } return mounted; } -// disabled coco end /*! + * \brief FileHandler::tmpUsable + * \details Checks if the temp folder is available 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, @@ -340,7 +372,7 @@ // if it is breaks // else adds the file to the list and continues. // DEBUG: qDebug() << "%" << totalSizeStorage << totalSizeFiles << totalSizeRetain << totalSizeFiles - totalSizeRetain << vRetainPercent; - quint64 totalSizeRemoved = 0; + quint64 totalSizeRemoved = 0; Q_UNUSED(totalSizeRemoved); for (auto it = fileInfoListAll.crbegin(); it != fileInfoListAll.crend(); ++it) { // (totalSizeFiles <= totalSizeRetain) has been checked above and didn't return; , // so at least one file should be checked and then check again in the loop.