@@ -46,6 +46,7 @@ namespace {
46
46
// base query used to select file record objects, used in combination with WHERE statements.
47
47
const auto getFileRecordQueryC = QByteArrayLiteral(" SELECT path, inode, modtime, type, md5, fileid, remotePerm, filesize,"
48
48
" ignoredChildrenRemote, contentchecksumtype.name || ':' || contentChecksum,"
49
+ " hasDirtyPlaceholder"
49
50
" FROM metadata"
50
51
" LEFT JOIN checksumtype as contentchecksumtype ON metadata.contentChecksumTypeId == contentchecksumtype.id " );
51
52
}
@@ -66,6 +67,7 @@ static void fillFileRecordFromGetQuery(SyncJournalFileRecord &rec, SqlQuery &que
66
67
rec._fileSize = query.int64Value (7 );
67
68
rec._serverHasIgnoredFiles = (query.intValue (8 ) > 0 );
68
69
rec._checksumHeader = query.baValue (9 );
70
+ rec._hasDirtyPlaceholder = query.intValue (10 );
69
71
}
70
72
71
73
static QByteArray defaultJournalMode (const QString &dbPath)
@@ -384,6 +386,7 @@ bool SyncJournalDb::checkConnect()
384
386
// ignoredChildrenRemote
385
387
// contentChecksum
386
388
// contentChecksumTypeId
389
+ // hasDirtyPlaceholder
387
390
" PRIMARY KEY(phash)"
388
391
" );" );
389
392
@@ -745,6 +748,22 @@ bool SyncJournalDb::updateMetadataTableStructure()
745
748
commitInternal (QStringLiteral (" update database structure: add contentChecksumTypeId col" ));
746
749
}
747
750
751
+ if (columns.indexOf (" hasDirtyPlaceholder" ) == -1 ) {
752
+ SqlQuery addDirtyQuery (_db);
753
+ addDirtyQuery.prepare (" ALTER TABLE metadata ADD COLUMN hasDirtyPlaceholder BOOLEAN;" );
754
+ if (!addDirtyQuery.exec ()) {
755
+ sqlFail (QStringLiteral (" updateMetadataTableStructure: add hasDirtyPlaceholder column" ), addDirtyQuery);
756
+ re = false ;
757
+ }
758
+ SqlQuery dirtyIndex (_db);
759
+ dirtyIndex.prepare (" CREATE INDEX hasDirtyPlaceholderIndex ON metadata(path) WHERE hasDirtyPlaceholder=TRUE;" );
760
+ if (!dirtyIndex.exec ()) {
761
+ sqlFail (QStringLiteral (" updateMetadataTableStructure: add index on hasDirtyPlaceholder column" ), dirtyIndex);
762
+ re = false ;
763
+ }
764
+ commitInternal (QStringLiteral (" update database structure: add hasDirtyPlaceholder col" ));
765
+ }
766
+
748
767
auto uploadInfoColumns = tableColumns (" uploadinfo" );
749
768
if (uploadInfoColumns.isEmpty ())
750
769
return false ;
@@ -882,7 +901,7 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
882
901
qCInfo (lcDb) << " Updating file record for path:" << record._path << " inode:" << record._inode
883
902
<< " modtime:" << record._modtime << " type:" << record._type
884
903
<< " etag:" << record._etag << " fileId:" << record._fileId << " remotePerm:" << record._remotePerm .toString ()
885
- << " fileSize:" << record._fileSize << " checksum:" << record._checksumHeader ;
904
+ << " fileSize:" << record._fileSize << " checksum:" << record._checksumHeader << " hasDirtyPlaceholder: " << record. _hasDirtyPlaceholder ;
886
905
887
906
const qint64 phash = getPHash (record._path );
888
907
if (checkConnect ()) {
@@ -899,8 +918,8 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
899
918
const auto checksumHeader = ChecksumHeader::parseChecksumHeader (record._checksumHeader );
900
919
int contentChecksumTypeId = mapChecksumType (checksumHeader.type ());
901
920
const auto query = _queryManager.get (PreparedSqlQueryManager::SetFileRecordQuery, QByteArrayLiteral (" INSERT OR REPLACE INTO metadata "
902
- " (phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentChecksum, contentChecksumTypeId) "
903
- " VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16);" ),
921
+ " (phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentChecksum, contentChecksumTypeId, hasDirtyPlaceholder ) "
922
+ " VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17 );" ),
904
923
_db);
905
924
if (!query) {
906
925
return query->error ();
@@ -922,6 +941,7 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
922
941
query->bindValue (14 , record._serverHasIgnoredFiles ? 1 : 0 );
923
942
query->bindValue (15 , checksumHeader.checksum ());
924
943
query->bindValue (16 , contentChecksumTypeId);
944
+ query->bindValue (17 , record._hasDirtyPlaceholder );
925
945
926
946
if (!query->exec ()) {
927
947
return query->error ();
@@ -2289,6 +2309,28 @@ SyncJournalDb::~SyncJournalDb()
2289
2309
close ();
2290
2310
}
2291
2311
2312
+ const QVector<SyncJournalFileRecord> SyncJournalDb::getFileRecordsWithDirtyPlaceholders () const
2313
+ {
2314
+ QMutexLocker locker (&_mutex);
2315
+
2316
+ if (OC_ENSURE (isOpen ())) {
2317
+ const auto query = _queryManager.get (PreparedSqlQueryManager::GetFileReocrdsWithDirtyPlaceholdersQuery, getFileRecordQueryC + QByteArrayLiteral (" WHERE hasDirtyPlaceholder=TRUE" ), const_cast <SyncJournalDb *>(this )->_db );
2318
+ if (!OC_ENSURE (query)) {
2319
+ return {};
2320
+ }
2321
+ if (!OC_ENSURE (query->exec ())) {
2322
+ return {};
2323
+ }
2324
+ QVector<SyncJournalFileRecord> out;
2325
+ while (query->next ().hasData ) {
2326
+ SyncJournalFileRecord rec;
2327
+ fillFileRecordFromGetQuery (rec, *query);
2328
+ out.append (rec);
2329
+ }
2330
+ return out;
2331
+ }
2332
+ return {};
2333
+ }
2292
2334
2293
2335
bool operator ==(const SyncJournalDb::DownloadInfo &lhs,
2294
2336
const SyncJournalDb::DownloadInfo &rhs)
0 commit comments