Skip to content

Commit

Permalink
Report available storage before syncing in diagnostic logs (#3523)
Browse files Browse the repository at this point in the history
* getAvailableStorage and getTotalStorage methods moved to core utils

* code layout fix

* enhancement plus bytesToHumanSize moved to CoreUtils

* last adjustment

* forcing CI run

* ci rerun

* layout fix
  • Loading branch information
VitorVieiraZ committed Jul 1, 2024
1 parent 33ff5a8 commit b9d080f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 21 deletions.
22 changes: 1 addition & 21 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,27 +535,7 @@ QString InputUtils::filesToString( QList<MerginFile> files )

QString InputUtils::bytesToHumanSize( double bytes )
{
const int precision = 1;
if ( bytes < 1e-5 )
{
return "0.0";
}
else if ( bytes < 1024.0 * 1024.0 )
{
return QString::number( bytes / 1024.0, 'f', precision ) + " KB";
}
else if ( bytes < 1024.0 * 1024.0 * 1024.0 )
{
return QString::number( bytes / 1024.0 / 1024.0, 'f', precision ) + " MB";
}
else if ( bytes < 1024.0 * 1024.0 * 1024.0 * 1024.0 )
{
return QString::number( bytes / 1024.0 / 1024.0 / 1024.0, 'f', precision ) + " GB";
}
else
{
return QString::number( bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0, 'f', precision ) + " TB";
}
return CoreUtils::bytesToHumanSize( bytes );
}

bool InputUtils::acquireCameraPermission()
Expand Down
52 changes: 52 additions & 0 deletions core/coreutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QTextStream>
#include <QCryptographicHash>
#include <QRegularExpression>
#include <QStorageInfo>

#include "qcoreapplication.h"

Expand Down Expand Up @@ -283,3 +284,54 @@ QString CoreUtils::nameAbbr( const QString &name, const QString &email )

return email.left( 2 ).toUpper();
}

QString CoreUtils::getAvailableDeviceStorage()
{
QString appDir = QCoreApplication::applicationDirPath();
QStorageInfo storageInfo( appDir );

if ( storageInfo.isValid() && storageInfo.isReady() )
{
return bytesToHumanSize( storageInfo.bytesAvailable() );
}

return "N/A";
}

QString CoreUtils::getTotalDeviceStorage()
{
QString appDir = QCoreApplication::applicationDirPath();
QStorageInfo storageInfo( appDir );

if ( storageInfo.isValid() && storageInfo.isReady() )
{
return bytesToHumanSize( storageInfo.bytesTotal() );
}

return "N/A";
}

QString CoreUtils::bytesToHumanSize( double bytes )
{
const int precision = 1;
if ( bytes < 1e-5 )
{
return "0.0";
}
else if ( bytes < 1024.0 * 1024.0 )
{
return QString::number( bytes / 1024.0, 'f', precision ) + " KB";
}
else if ( bytes < 1024.0 * 1024.0 * 1024.0 )
{
return QString::number( bytes / 1024.0 / 1024.0, 'f', precision ) + " MB";
}
else if ( bytes < 1024.0 * 1024.0 * 1024.0 * 1024.0 )
{
return QString::number( bytes / 1024.0 / 1024.0 / 1024.0, 'f', precision ) + " GB";
}
else
{
return QString::number( bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0, 'f', precision ) + " TB";
}
}
16 changes: 16 additions & 0 deletions core/coreutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ class CoreUtils
static QString deviceUuid();

static const QString QSETTINGS_APP_GROUP_NAME;

/**
* Returns available device storage
*/
static QString getAvailableDeviceStorage();

/**
* Returns total device storage
*/
static QString getTotalDeviceStorage();

/**
* Converts bytes to human readable size (e.g. 1GB, 500MB)
*/
static QString bytesToHumanSize( double bytes );

private:
static QString sLogFile;
static int CHECKSUM_CHUNK_SIZE;
Expand Down
4 changes: 4 additions & 0 deletions core/merginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,10 @@ void MerginApi::startProjectPull( const QString &projectFullName )
[]( const DownloadQueueItem & a, const DownloadQueueItem & b ) { return a.size > b.size; }
);

CoreUtils::log( "pull " + projectFullName, QStringLiteral( "%1 of available device storage, %2 of total device storage" )
.arg( CoreUtils::getAvailableDeviceStorage() )
.arg( CoreUtils::getTotalDeviceStorage() ) );

CoreUtils::log( "pull " + projectFullName, QStringLiteral( "%1 update tasks, %2 items to download (total size %3 bytes)" )
.arg( transaction.pullTasks.count() )
.arg( transaction.downloadQueue.count() )
Expand Down

0 comments on commit b9d080f

Please sign in to comment.