Index: sources/device/DeviceController.cpp =================================================================== diff -u -raf0eb3014623933ce3cffac481477d11b3b9c5b5 -r2afdc76a7d8f97a518da0158e9bd08217de41a97 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision af0eb3014623933ce3cffac481477d11b3b9c5b5) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 2afdc76a7d8f97a518da0158e9bd08217de41a97) @@ -7,7 +7,7 @@ * * \file DeviceController.cpp * \author (last) Behrouz NematiPour - * \date (last) 18-Jul-2023 + * \date (last) 19-Jul-2023 * \author (original) Behrouz NematiPour * \date (original) 03-Jun-2021 * @@ -236,6 +236,10 @@ #ifdef BUILD_FOR_TARGET usbCheck(); sdcardSpaceCheck(); + + // The treatment logs are held in a separate partition from the unencrypted + // logs and need a separate disk space usage check + settingsPartitionSpaceCheck(); #endif } @@ -276,7 +280,12 @@ qint64 mCTotal = 0; - mCIsReady = driveSpaceCheck(Storage::SDCard_Base_Path_Name, mCTotal, mCAvailable, &mCIsReadOnly); + bool isMounted = FileHandler::isMounted(Storage::SDCard_Base_Path_Name); + QString pathToCheckSpace = isMounted ? Storage::SDCard_Base_Path_Name : Storage::Standard_tmp; + mCIsReady = driveSpaceCheck(pathToCheckSpace, mCTotal, mCAvailable, &mCIsReadOnly); + + //DEBUG: qDebug()<< "Checking space for path of : " << pathToCheckSpace << " mCTotal " << mCTotal << " available " << mCAvailable; + if (mOIsReadOnly != mCIsReadOnly || mOIsReady != mCIsReady || ! mInitialized ) { mOIsReadOnly = mCIsReadOnly; mOIsReady = mCIsReady; @@ -357,7 +366,58 @@ // << mCAvailable ; } +/*! + * \brief DeviceController::settingsPartitionSpaceCheck + * \details Checks the disk space of the encrypted partition + */ +void DeviceController::settingsPartitionSpaceCheck() +{ + static bool mInitialized = false; + // Old Info ; // Current info + static bool mOIsReady = false; bool mCIsReady = false; + static bool mOIsReadOnly = false; bool mCIsReadOnly = false; + static qint64 mOAvailable = 0; qint64 mCAvailable = 0; + static quint8 mOPercent = 0; quint8 mCPercent = 0; + qint64 mCTotal = 0; + mCIsReady = driveSpaceCheck(Storage::Settings_Path(), mCTotal, mCAvailable, &mCIsReadOnly); + + //DEBUG: qDebug()<< "Checking space for path of : " << Storage::Settings_Path() << " mCTotal " << mCTotal << " available " << mCAvailable; + + if (mOIsReadOnly != mCIsReadOnly || mOIsReady != mCIsReady || ! mInitialized ) { + mOIsReadOnly = mCIsReadOnly; + mOIsReady = mCIsReady; + mInitialized = true; + //DEBUG:0: qDebug() << " ~~~~~~~~~~ " << __FUNCTION__ << mInitialized << mCIsReady << mOIsReady << mCIsReadOnly << mOIsReadOnly; + emit didSettingsPartitionStateChange(mCIsReady, mCIsReadOnly); + } + //NOTE: this if block has to be independent of the mOIsReady != mCIsReady + // because current and old may be the same all the time and then this if block will not execute + // and reaches to the log and fills the log unnecessarily. + if (! mCIsReady ) { + mOPercent = 0; + mOAvailable = 0; + emit didSettingsPartitionSpaceChange(mCIsReady, mCTotal, mCAvailable, mCPercent); + return; + } + + mCPercent = mCTotal ? ((100 * mCAvailable) / mCTotal) : 0; + if (mCPercent < _minRequiredAvailableSpacePercent) { + LOG_DEBUG(QString("Settings partition space lower than %1%").arg(_minRequiredAvailableSpacePercent)); + emit didSettingsPartitionSpaceChange(mCIsReady, mCTotal, mCAvailable, mCPercent); + emit didSDCardSpaceTooLow(_minRequiredAvailableSpacePercent); + } + + /// DEBUG: qDebug() << Storage::SDCard_Base_Path_Name << mCIsReady << mOTotal << mCTotal << (mOTotal == mCTotal) << mOAvailable << mCAvailable << (mOAvailable == mCAvailable) << mPercent << mCIsReadOnly; + if (mOPercent != mCPercent && mOAvailable != mCAvailable ) { + mOPercent = mCPercent ; + mOAvailable = mCAvailable ; + emit didSettingsPartitionSpaceChange(mCIsReady, mCTotal, mCAvailable, mCPercent); + /// DEBUG: qDebug() << Storage::SDCard_Base_Path_Name << mCIsReady << mCTotal << mCAvailable << mPercent ; + } +} + + /*! * \brief DeviceController::usbError * \details Logs any error which has been happened