Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Oct 24, 2024
1 parent 74216ac commit 5cc32f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/core/qfieldcloudprojectsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,20 +1037,22 @@ void QFieldCloudProjectsModel::projectDownload( const QString &projectId )
const int fileSize = fileObject.value( QStringLiteral( "size" ) ).toInt();
const QString fileName = fileObject.value( QStringLiteral( "name" ) ).toString();
const QString projectFileName = QStringLiteral( "%1/%2/%3/%4" ).arg( QFieldCloudUtils::localCloudDirectory(), mUsername, projectId, fileName );
const QString cloudChecksum = fileObject.value( QStringLiteral( "md5sum" ) ).toString();
const QString localChecksum = FileUtils::fileEtag( projectFileName );
// NOTE the cloud API is giving the false impression that the file keys `md5sum` is having a MD5 or another checksum.
// This actually is an Object Storage (S3) implementation specific ETag.
const QString cloudEtag = fileObject.value( QStringLiteral( "md5sum" ) ).toString();
const QString localEtag = FileUtils::fileEtag( projectFileName );

if (
!fileObject.value( QStringLiteral( "size" ) ).isDouble()
|| fileName.isEmpty()
|| cloudChecksum.isEmpty() )
|| cloudEtag.isEmpty() )
{
QgsLogger::debug( QStringLiteral( "Project %1: package in \"files\" list does not contain the expected fields: size(int), name(string), md5sum(string)" ).arg( projectId ) );
emit projectDownloadFinished( projectId, tr( "Latest package data structure error." ) );
return;
}

if ( cloudChecksum == localChecksum )
if ( cloudEtag == localEtag )
continue;

project->downloadFileTransfers.insert( fileName, FileTransfer( fileName, fileSize ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class QFIELD_CORE_EXPORT FileUtils : public QObject
Q_INVOKABLE static QByteArray fileChecksum( const QString &fileName, const QCryptographicHash::Algorithm hashAlgorithm );

/**
* Returns an S3 ETag of a file. An empty string will be returned if it cannot be calculated.
* Returns an Object Storage (S3) ETag of a file. An empty string will be returned if it cannot be calculated.
* \param fileName file name to get checksum of
* \param partSize maximum size used to divide the file content into parts
* \return QString Etag value
Expand Down

1 comment on commit 5cc32f8

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.