_stopWatch.start();
- // do whatever is needed to add a checksum to the http upload request.
- // in any case, the validator will emit signal startUpload to let the flow
- // continue in slotStartUpload here.
+ auto supportedChecksumTypes = _propagator->account()->capabilities().supportedChecksumTypes();
+
+ // If we already have a checksum header and the checksum type is supported
+ // by the server, we keep that - otherwise recompute.
+ if (!_item->_checksumHeader.isEmpty()) {
+ QByteArray checksumType;
+ QByteArray checksum;
+ if (parseChecksumHeader(_item->_checksumHeader, &checksumType, &checksum)
+ && supportedChecksumTypes.contains(checksumType)) {
+ // TODO: We could validate the old checksum and thereby determine whether
+ // an upload is necessary or not.
+ slotStartUpload(checksumType, checksum);
+ return;
+ }
+ }
+
+ // Compute a new checksum.
auto computeChecksum = new ComputeChecksum(this);
// If the config file does not specify a checksum type but the
- // server supports it choose a type based on that.
+ // server supports it, choose a type based on that.
if (computeChecksum->checksumType().isEmpty()) {
- auto checksumTypes = _propagator->account()->capabilities().supportedChecksumTypes();
- if (!checksumTypes.isEmpty()) {
+ if (!supportedChecksumTypes.isEmpty()) {
// TODO: We might want to prefer some types over others instead
// of choosing the first.
- computeChecksum->setChecksumType(checksumTypes.first());
+ computeChecksum->setChecksumType(supportedChecksumTypes.first());
}
}
void PropagateUploadFileQNAM::slotStartUpload(const QByteArray& checksumType, const QByteArray& checksum)
{
+ // Store the computed checksum in the database, if different
+ auto newChecksumHeader = makeChecksumHeader(checksumType, checksum);
+ if (newChecksumHeader != _item->_checksumHeader) {
+ _item->_checksumHeader = newChecksumHeader;
+ _propagator->_journal->updateFileRecordChecksumHeader(_item->_file, _item->_checksumHeader);
+ }
+
const QString fullFilePath = _propagator->getFilePath(_item->_file);
- _item->_checksumHeader = makeChecksumHeader(checksumType, checksum);
if (!FileSystem::fileExists(fullFilePath)) {
done(SyncFileItem::SoftError, tr("File Removed"));
"(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, checksumHeader) "
"VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15);" );
+ _setFileRecordChecksumHeaderQuery.reset(new SqlQuery(_db) );
+ _setFileRecordChecksumHeaderQuery->prepare("UPDATE metadata SET checksumHeader = ?2 WHERE phash == ?1;");
+
_getDownloadInfoQuery.reset(new SqlQuery(_db) );
_getDownloadInfoQuery->prepare( "SELECT tmpfile, etag, errorcount FROM "
"downloadinfo WHERE path=?1" );
return 0;
}
+bool SyncJournalDb::updateFileRecordChecksumHeader(const QString &filename, const QByteArray &checksumHeader)
+{
+ QMutexLocker locker(&_mutex);
+
+ qlonglong phash = getPHash(filename);
+ if( !checkConnect() ) {
+ qDebug() << "Failed to connect database.";
+ return false;
+ }
+
+ auto & query = _setFileRecordChecksumHeaderQuery;
+
+ query->reset();
+ query->bindValue(1, QString::number(phash));
+ query->bindValue(2, checksumHeader);
+
+ if( !query->exec() ) {
+ qWarning() << "Error SQL statement setFileRecordChecksumHeaderQuery: "
+ << query->lastQuery() << " :"
+ << query->error();
+ return false;
+ }
+
+ qDebug() << query->lastQuery() << phash << checksumHeader;
+
+ query->reset();
+ return true;
+}
+
static void toDownloadInfo(SqlQuery &query, SyncJournalDb::DownloadInfo * res)
{
bool ok = true;
bool setFileRecord( const SyncJournalFileRecord& record );
bool deleteFileRecord( const QString& filename, bool recursively = false );
int getFileRecordCount();
+ bool updateFileRecordChecksumHeader(const QString& filename, const QByteArray& checksumHeader);
bool exists();
void walCheckpoint();
int _transaction;
QScopedPointer<SqlQuery> _getFileRecordQuery;
QScopedPointer<SqlQuery> _setFileRecordQuery;
+ QScopedPointer<SqlQuery> _setFileRecordChecksumHeaderQuery;
QScopedPointer<SqlQuery> _getDownloadInfoQuery;
QScopedPointer<SqlQuery> _setDownloadInfoQuery;
QScopedPointer<SqlQuery> _deleteDownloadInfoQuery;