Skip to content

Commit

Permalink
Checksums: Compute content checksum on download owncloud#4375
Browse files Browse the repository at this point in the history
  • Loading branch information
ckamm committed Mar 2, 2016
1 parent 7ed7512 commit d6d3502
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
39 changes: 32 additions & 7 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,11 @@ void PropagateDownloadFileQNAM::slotGetFinished()
}

// Do checksum validation for the download. If there is no checksum header, the validator
// will also emit the validated() signal to continue the flow in slot downloadFinished()
// will also emit the validated() signal to continue the flow in slot transmissionChecksumValidated()
// as this is (still) also correct.
ValidateChecksumHeader *validator = new ValidateChecksumHeader(this);
connect(validator, SIGNAL(validated(QByteArray,QByteArray)),
SLOT(downloadFinished(QByteArray,QByteArray)));
SLOT(transmissionChecksumValidated(QByteArray,QByteArray)));
connect(validator, SIGNAL(validationFailed(QString)),
SLOT(slotChecksumFail(QString)));
auto checksumHeader = job->reply()->rawHeader(checkSumHeaderC);
Expand Down Expand Up @@ -638,13 +638,38 @@ static void handleRecallFile(const QString &fn)
}
} // end namespace

void PropagateDownloadFileQNAM::downloadFinished(const QByteArray& transportChecksumType,
const QByteArray& transportChecksum)

void PropagateDownloadFileQNAM::transmissionChecksumValidated(const QByteArray &checksumType, const QByteArray &checksum)
{
// by default, reuse the transport checksum as content checksum
_item->_contentChecksum = transportChecksum;
_item->_contentChecksumType = transportChecksumType;
const auto theContentChecksumType = contentChecksumType();

// Reuse transmission checksum as content checksum.
//
// We could do this more aggressively and accept both MD5 and SHA1
// instead of insisting on the exactly correct checksum type.
if (theContentChecksumType == checksumType || theContentChecksumType.isEmpty()) {
return contentChecksumComputed(checksumType, checksum);
}

// Compute the content checksum.
auto computeChecksum = new ComputeChecksum(this);
computeChecksum->setChecksumType(theContentChecksumType);

connect(computeChecksum, SIGNAL(done(QByteArray,QByteArray)),
SLOT(contentChecksumComputed(QByteArray,QByteArray)));
computeChecksum->start(_tmpFile.fileName());
}

void PropagateDownloadFileQNAM::contentChecksumComputed(const QByteArray &checksumType, const QByteArray &checksum)
{
_item->_contentChecksum = checksum;
_item->_contentChecksumType = checksumType;

downloadFinished();
}

void PropagateDownloadFileQNAM::downloadFinished()
{
QString fn = _propagator->getFilePath(_item->_file);

// In case of file name clash, report an error
Expand Down
5 changes: 3 additions & 2 deletions src/libsync/propagatedownload.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class PropagateDownloadFileQNAM : public PropagateItemJob {
private slots:
void slotGetFinished();
void abort() Q_DECL_OVERRIDE;
void downloadFinished(const QByteArray& transportChecksumType = QByteArray(),
const QByteArray &transportChecksum = QByteArray());
void transmissionChecksumValidated(const QByteArray& checksumType, const QByteArray& checksum);
void contentChecksumComputed(const QByteArray& checksumType, const QByteArray& checksum);
void downloadFinished();
void slotDownloadProgress(qint64,qint64);
void slotChecksumFail( const QString& errMsg );

Expand Down

0 comments on commit d6d3502

Please sign in to comment.