Index: sources/storage/Logger.cpp =================================================================== diff -u -r75e10e5c2ada62906baded5ba8731977e51b1357 -r1ed15b374613c81883e697cad25e55399e7abc17 --- sources/storage/Logger.cpp (.../Logger.cpp) (revision 75e10e5c2ada62906baded5ba8731977e51b1357) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 1ed15b374613c81883e697cad25e55399e7abc17) @@ -687,6 +687,10 @@ int result = 0; QString mSource = _logPathNames[vLogType]; QString mDestination = USB_Mount_Point; + + // Check USB disk space before proceeding + if ( !checkExportUSBSpace(vExportList, mSource) ) return false; + if ( vExportList.isEmpty() ) { // Copy Folder result = FileHandler::copyFolder( mSource, mDestination); @@ -703,3 +707,42 @@ } return result >= 0; // refer to QProcess::execute(hit F1 on execute) doc. } + +/*! + * \brief Logger::checkExportUSBSpace + * \details Check the USB to make sure there is enough space to accomodate exporting either a list of files or + * an entire folder at source + * \param vExportList - List of files to export + * \param vSource - The source path of the folder to export or the folder where files in list reside + * \return true if there is enough space on the USB for exporting the list of files or the entire directory, false otherwise + */ +bool Logger::checkExportUSBSpace(const Gui::GuiStringIndexMap &vExportList, const QString &vSource) +{ + qint64 totalSpace = 0; + qint64 availableSpace = 0; + + bool isUSBDiskReady = _DeviceController.driveSpaceCheck(Storage::USB_Mount_Point, totalSpace, availableSpace); + if ( !isUSBDiskReady ) return false; + + qint64 totalExportSizeExpected = 0; + + if ( vExportList.isEmpty() ) { + // expecting to export an entire directory, get size of directory + totalExportSizeExpected = FileHandler::totalDirSize(vSource); + }else{ + // exporting individual files, need to get total size of selected files + Gui::GuiStringIndexMapIterator it(vExportList); + QDir srcDir = QFileInfo (vSource).absoluteDir(); + + while ( it.hasNext() ) { + it.next(); + auto fileName = it.value(); + QFile srcFile = QFile (vSource + fileName); + totalExportSizeExpected += srcFile.size(); + //DEBUG: qDebug()<< "FILE " << srcFile.fileName() << " size " << srcFile.size(); + } + } + + //DEBUG: qDebug()<< "available " << availableSpace << " | total "<< totalSpace << " | size copying " << totalExportSizeExpected << " | expecting after " << (availableSpace + totalExportSizeExpected); + return (availableSpace + totalExportSizeExpected) < totalSpace; +}