зеркало из https://github.com/nextcloud/desktop.git
Родитель
566131209d
Коммит
496b1e907d
|
@ -246,7 +246,7 @@ void PropagateUploadFileQNAM::slotStartUpload(const QByteArray& checksumType, co
|
||||||
|| checksum != _item->_transmissionChecksum) {
|
|| checksum != _item->_transmissionChecksum) {
|
||||||
_item->_transmissionChecksum = checksum;
|
_item->_transmissionChecksum = checksum;
|
||||||
_item->_transmissionChecksumType = checksumType;
|
_item->_transmissionChecksumType = checksumType;
|
||||||
_propagator->_journal->updateFileRecordChecksumHeader(
|
_propagator->_journal->updateFileRecordChecksum(
|
||||||
_item->_file, checksum, checksumType);
|
_item->_file, checksum, checksumType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -471,7 +471,7 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
|
||||||
// the file system in the DB, this is to avoid spurious upload on the next sync
|
// the file system in the DB, this is to avoid spurious upload on the next sync
|
||||||
item->_modtime = file->other.modtime;
|
item->_modtime = file->other.modtime;
|
||||||
|
|
||||||
_journal->setFileRecord(SyncJournalFileRecord(*item, _localPath + item->_file));
|
_journal->updateFileRecordMetadata(SyncJournalFileRecord(*item, _localPath + item->_file));
|
||||||
item->_should_update_metadata = false;
|
item->_should_update_metadata = false;
|
||||||
}
|
}
|
||||||
if (item->_isDirectory && file->should_update_metadata) {
|
if (item->_isDirectory && file->should_update_metadata) {
|
||||||
|
|
|
@ -369,7 +369,17 @@ bool SyncJournalDb::checkConnect()
|
||||||
"VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16);" );
|
"VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16);" );
|
||||||
|
|
||||||
_setFileRecordChecksumQuery.reset(new SqlQuery(_db) );
|
_setFileRecordChecksumQuery.reset(new SqlQuery(_db) );
|
||||||
_setFileRecordChecksumQuery->prepare("UPDATE metadata SET transmissionChecksum = ?2, transmissionChecksumTypeId = ?3 WHERE phash == ?1;");
|
_setFileRecordChecksumQuery->prepare(
|
||||||
|
"UPDATE metadata"
|
||||||
|
" SET transmissionChecksum = ?2, transmissionChecksumTypeId = ?3"
|
||||||
|
" WHERE phash == ?1;");
|
||||||
|
|
||||||
|
_setFileRecordMetadataQuery.reset(new SqlQuery(_db) );
|
||||||
|
_setFileRecordMetadataQuery->prepare(
|
||||||
|
"UPDATE metadata"
|
||||||
|
" SET inode=?2, mode=?3, modtime=?4, type=?5, md5=?6, fileid=?7,"
|
||||||
|
" remotePerm=?8, filesize=?9, ignoredChildrenRemote=?10"
|
||||||
|
" WHERE phash == ?1;");
|
||||||
|
|
||||||
_getDownloadInfoQuery.reset(new SqlQuery(_db) );
|
_getDownloadInfoQuery.reset(new SqlQuery(_db) );
|
||||||
_getDownloadInfoQuery->prepare( "SELECT tmpfile, etag, errorcount FROM "
|
_getDownloadInfoQuery->prepare( "SELECT tmpfile, etag, errorcount FROM "
|
||||||
|
@ -872,9 +882,9 @@ int SyncJournalDb::getFileRecordCount()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyncJournalDb::updateFileRecordChecksumHeader(const QString& filename,
|
bool SyncJournalDb::updateFileRecordChecksum(const QString& filename,
|
||||||
const QByteArray& transmisisonChecksum,
|
const QByteArray& transmisisonChecksum,
|
||||||
const QByteArray& transmissionChecksumType)
|
const QByteArray& transmissionChecksumType)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
|
|
||||||
|
@ -893,7 +903,7 @@ bool SyncJournalDb::updateFileRecordChecksumHeader(const QString& filename,
|
||||||
query->bindValue(3, checksumTypeId);
|
query->bindValue(3, checksumTypeId);
|
||||||
|
|
||||||
if( !query->exec() ) {
|
if( !query->exec() ) {
|
||||||
qWarning() << "Error SQL statement setFileRecordChecksumHeaderQuery: "
|
qWarning() << "Error SQL statement setFileRecordChecksumQuery: "
|
||||||
<< query->lastQuery() << " :"
|
<< query->lastQuery() << " :"
|
||||||
<< query->error();
|
<< query->error();
|
||||||
return false;
|
return false;
|
||||||
|
@ -906,6 +916,52 @@ bool SyncJournalDb::updateFileRecordChecksumHeader(const QString& filename,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SyncJournalDb::updateFileRecordMetadata(const SyncJournalFileRecord& record)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&_mutex);
|
||||||
|
|
||||||
|
qlonglong phash = getPHash(record._path);
|
||||||
|
QString etag( record._etag );
|
||||||
|
if( etag.isEmpty() ) etag = "";
|
||||||
|
QString fileId( record._fileId);
|
||||||
|
if( fileId.isEmpty() ) fileId = "";
|
||||||
|
QString remotePerm (record._remotePerm);
|
||||||
|
if (remotePerm.isEmpty()) remotePerm = QString(); // have NULL in DB (vs empty)
|
||||||
|
|
||||||
|
if( !checkConnect() ) {
|
||||||
|
qDebug() << "Failed to connect database.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto & query = _setFileRecordMetadataQuery;
|
||||||
|
|
||||||
|
query->reset();
|
||||||
|
query->bindValue(1, QString::number(phash));
|
||||||
|
query->bindValue(2, record._inode);
|
||||||
|
query->bindValue(3, record._mode);
|
||||||
|
query->bindValue(4, QString::number(Utility::qDateTimeToTime_t(record._modtime)));
|
||||||
|
query->bindValue(5, QString::number(record._type));
|
||||||
|
query->bindValue(6, etag);
|
||||||
|
query->bindValue(7, fileId);
|
||||||
|
query->bindValue(8, remotePerm);
|
||||||
|
query->bindValue(9, record._fileSize);
|
||||||
|
query->bindValue(10, record._serverHasIgnoredFiles ? 1 : 0);
|
||||||
|
|
||||||
|
if( !query->exec() ) {
|
||||||
|
qWarning() << "Error SQL statement setFileRecordMetadataQuery: "
|
||||||
|
<< query->lastQuery() << " :"
|
||||||
|
<< query->error();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << query->lastQuery() << record._path << record._inode << record._mode << record._modtime
|
||||||
|
<< record._type << etag << fileId << remotePerm << record._fileSize
|
||||||
|
<< record._serverHasIgnoredFiles;
|
||||||
|
|
||||||
|
query->reset();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void toDownloadInfo(SqlQuery &query, SyncJournalDb::DownloadInfo * res)
|
static void toDownloadInfo(SqlQuery &query, SyncJournalDb::DownloadInfo * res)
|
||||||
{
|
{
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
|
@ -42,9 +42,10 @@ public:
|
||||||
bool setFileRecord( const SyncJournalFileRecord& record );
|
bool setFileRecord( const SyncJournalFileRecord& record );
|
||||||
bool deleteFileRecord( const QString& filename, bool recursively = false );
|
bool deleteFileRecord( const QString& filename, bool recursively = false );
|
||||||
int getFileRecordCount();
|
int getFileRecordCount();
|
||||||
bool updateFileRecordChecksumHeader(const QString& filename,
|
bool updateFileRecordChecksum(const QString& filename,
|
||||||
const QByteArray& transmisisonChecksum,
|
const QByteArray& transmisisonChecksum,
|
||||||
const QByteArray& transmissionChecksumType);
|
const QByteArray& transmissionChecksumType);
|
||||||
|
bool updateFileRecordMetadata(const SyncJournalFileRecord& record);
|
||||||
bool exists();
|
bool exists();
|
||||||
void walCheckpoint();
|
void walCheckpoint();
|
||||||
|
|
||||||
|
@ -168,6 +169,7 @@ private:
|
||||||
QScopedPointer<SqlQuery> _getFileRecordQuery;
|
QScopedPointer<SqlQuery> _getFileRecordQuery;
|
||||||
QScopedPointer<SqlQuery> _setFileRecordQuery;
|
QScopedPointer<SqlQuery> _setFileRecordQuery;
|
||||||
QScopedPointer<SqlQuery> _setFileRecordChecksumQuery;
|
QScopedPointer<SqlQuery> _setFileRecordChecksumQuery;
|
||||||
|
QScopedPointer<SqlQuery> _setFileRecordMetadataQuery;
|
||||||
QScopedPointer<SqlQuery> _getDownloadInfoQuery;
|
QScopedPointer<SqlQuery> _getDownloadInfoQuery;
|
||||||
QScopedPointer<SqlQuery> _setDownloadInfoQuery;
|
QScopedPointer<SqlQuery> _setDownloadInfoQuery;
|
||||||
QScopedPointer<SqlQuery> _deleteDownloadInfoQuery;
|
QScopedPointer<SqlQuery> _deleteDownloadInfoQuery;
|
||||||
|
|
|
@ -67,6 +67,26 @@ private slots:
|
||||||
SyncJournalFileRecord storedRecord = _db.getFileRecord("foo");
|
SyncJournalFileRecord storedRecord = _db.getFileRecord("foo");
|
||||||
QVERIFY(storedRecord == record);
|
QVERIFY(storedRecord == record);
|
||||||
|
|
||||||
|
// Update checksum
|
||||||
|
record._transmissionChecksum = "newchecksum";
|
||||||
|
record._transmissionChecksumType = "Adler32";
|
||||||
|
_db.updateFileRecordChecksum("foo", record._transmissionChecksum, record._transmissionChecksumType);
|
||||||
|
storedRecord = _db.getFileRecord("foo");
|
||||||
|
QVERIFY(storedRecord == record);
|
||||||
|
|
||||||
|
// Update metadata
|
||||||
|
record._inode = 12345;
|
||||||
|
record._modtime = dropMsecs(QDateTime::currentDateTime().addDays(1));
|
||||||
|
record._type = 7;
|
||||||
|
record._etag = "789FFF";
|
||||||
|
record._fileId = "efg";
|
||||||
|
record._remotePerm = "777";
|
||||||
|
record._mode = 12;
|
||||||
|
record._fileSize = 289055;
|
||||||
|
_db.updateFileRecordMetadata(record);
|
||||||
|
storedRecord = _db.getFileRecord("foo");
|
||||||
|
QVERIFY(storedRecord == record);
|
||||||
|
|
||||||
QVERIFY(_db.deleteFileRecord("foo"));
|
QVERIFY(_db.deleteFileRecord("foo"));
|
||||||
record = _db.getFileRecord("foo");
|
record = _db.getFileRecord("foo");
|
||||||
QVERIFY(!record.isValid());
|
QVERIFY(!record.isValid());
|
||||||
|
|
Загрузка…
Ссылка в новой задаче