Index: sources/storage/FileHandler.cpp =================================================================== diff -u -ra5c75192af33a9284e4b4886df0c337ba6fcc9f9 -rcf51c19d82d667644d7f70eaa521b43f908c7068 --- sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision a5c75192af33a9284e4b4886df0c337ba6fcc9f9) +++ 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) 15-Oct-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; @@ -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,