Index: sources/device/DeviceController.h =================================================================== diff -u -r15dffa44e42fe108caa6dd0dfbe659b192ee5323 -r1ed15b374613c81883e697cad25e55399e7abc17 --- sources/device/DeviceController.h (.../DeviceController.h) (revision 15dffa44e42fe108caa6dd0dfbe659b192ee5323) +++ sources/device/DeviceController.h (.../DeviceController.h) (revision 1ed15b374613c81883e697cad25e55399e7abc17) @@ -121,6 +121,9 @@ // to be able to kill the process automatically after the set time out. DEVICE_DEV_DEFINITION_LIST +public: + static bool driveSpaceCheck(const QString &vPath, qint64 &vTotalBytes, qint64 &vAvailableBytes, bool *vIsReadOnly = nullptr); + public slots: bool init(); bool init(QThread &vThread); @@ -161,8 +164,6 @@ bool usbSeek(QString &vDevice); - bool driveSpaceCheck(const QString &vPath, qint64 &vTotalBytes, qint64 &vAvailableBytes, bool *vIsReadOnly = nullptr); - template bool checkError(DeviceError::Scripts_Error_Enum vError, TModel &vModel,QString vExtraLogInfo = ""); DeviceError::Scripts_Error_Enum checkScript(QString &vScript, const QString &vShellScript); Index: sources/storage/FileHandler.cpp =================================================================== diff -u -r80b5e8f1ebb90c03c37d90d90cd2da3bd95d6803 -r1ed15b374613c81883e697cad25e55399e7abc17 --- sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision 80b5e8f1ebb90c03c37d90d90cd2da3bd95d6803) +++ sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision 1ed15b374613c81883e697cad25e55399e7abc17) @@ -439,6 +439,17 @@ // disabled coco end /*! + * \brief FileHandler::totalDirSize + * \details Determine the total space of the passed path + * \param vPath - the path to determine size of + * \return The size of the path passed. + */ +qint64 FileHandler::totalDirSize(const QString &vPath) +{ + return totalSize(find(vPath, QStringList() << "*.*")); +} + +/*! * \brief FileHandler::subFolders * \details Look for the sub-folder in folder vFolder. * \param vFolder - the folder to search for the sub folders. Index: sources/storage/FileHandler.h =================================================================== diff -u -r80b5e8f1ebb90c03c37d90d90cd2da3bd95d6803 -r1ed15b374613c81883e697cad25e55399e7abc17 --- sources/storage/FileHandler.h (.../FileHandler.h) (revision 80b5e8f1ebb90c03c37d90d90cd2da3bd95d6803) +++ sources/storage/FileHandler.h (.../FileHandler.h) (revision 1ed15b374613c81883e697cad25e55399e7abc17) @@ -75,6 +75,7 @@ static QFileInfoList find(const QString &vPath, QStringList vNameFilters, quint8 vRetainPercent); static QFileInfoList find(const QString &vPath, QStringList vNameFilters); static quint64 totalSize(const QFileInfoList &vFileInfoList); + static qint64 totalDirSize(const QString &vPath); static QStringList subFolders(const QString &vFolder); 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; +} Index: sources/storage/Logger.h =================================================================== diff -u -rc97b99199d1be46f7cfa99908308ce98c8578285 -r1ed15b374613c81883e697cad25e55399e7abc17 --- sources/storage/Logger.h (.../Logger.h) (revision c97b99199d1be46f7cfa99908308ce98c8578285) +++ sources/storage/Logger.h (.../Logger.h) (revision 1ed15b374613c81883e697cad25e55399e7abc17) @@ -146,6 +146,8 @@ QThread *_thread = nullptr; bool _init = false; + bool checkExportUSBSpace(const Gui::GuiStringIndexMap &vExportList, const QString &vSource); + public: void enableConsoleOut(bool vEnabled); void postInit();