Index: sources/storage/FileHandler.cpp =================================================================== diff -u -r5687815256ae070a9a207107088e3f72dd464da0 -r45a6996f6643db2f20520ba60e952c647b2d0501 --- sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision 5687815256ae070a9a207107088e3f72dd464da0) +++ sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision 45a6996f6643db2f20520ba60e952c647b2d0501) @@ -58,6 +58,22 @@ ++count; } +bool FileHandler::append(const QString &vSource, const QString &vTarget, bool vRemoveSource) { + bool ok = false; + QString content; + ok = read(vSource, content); + if ( ! ok ) goto lOut; + + ok = write(vTarget, content, true); + if ( ! ok ) goto lOut; + + if ( ! vRemoveSource ) goto lOut; + ok = QFile::remove(vSource); + if ( ! ok ) goto lOut; + +lOut: + return ok; +} /*! * \brief FileHandler::write * \details writes content vContent into the file vFileName. @@ -131,6 +147,30 @@ } /*! + * \brief FileHandler::backupFile + * \details Calls the gzip command + * The vPrepend file is prepended to the vDestination file, + * gets compressed with the name of the vDestination file appended with .gz + * The two files of vPrepend and vDestination will be delitted in this function. + * \param vSource - file to be prepended to the vDestination file before compression. + * \param vDestination - the file to be prepared and compressed, also the base name of the compressed file. + * \return NOT FINALIZED YET. + * \note THIS FUNCTION IS NOT TESTED DUE TO ISSUES IN RETURN VALUE CHECK OF TWO PIPED COMMAND. + */ +int FileHandler::backupFile(const QString &vPrepend, const QString &vDestination) +{ + QString cmd = QString("cat %1 %2 | gzip > %2.%3") + .arg(vPrepend) + .arg(vDestination) + .arg(Storage::gzipExt) + ; + int result = QProcess::execute(cmd, {}); + QFile::remove(vPrepend); + QFile::remove(vDestination); + return result; +} + +/*! * \brief FileHandler::copyFolder * \details Copies all the file and folders recursively. * \param vSource - The source folder