45
45
namespace {
46
46
const auto getFileRecordQueryC = QByteArrayLiteral(" SELECT path, inode, modtime, type, md5, fileid, remotePerm, filesize,"
47
47
" ignoredChildrenRemote, contentchecksumtype.name || ':' || contentChecksum,"
48
+ " hasDirtyPlaceholder"
48
49
" FROM metadata"
49
50
" LEFT JOIN checksumtype as contentchecksumtype ON metadata.contentChecksumTypeId == contentchecksumtype.id " );
50
51
}
@@ -65,6 +66,7 @@ static void fillFileRecordFromGetQuery(SyncJournalFileRecord &rec, SqlQuery &que
65
66
rec._fileSize = query.int64Value (7 );
66
67
rec._serverHasIgnoredFiles = (query.intValue (8 ) > 0 );
67
68
rec._checksumHeader = query.baValue (9 );
69
+ rec._hasDirtyPlaceholder = query.intValue (10 );
68
70
}
69
71
70
72
static QByteArray defaultJournalMode (const QString &dbPath)
@@ -383,6 +385,7 @@ bool SyncJournalDb::checkConnect()
383
385
// ignoredChildrenRemote
384
386
// contentChecksum
385
387
// contentChecksumTypeId
388
+ // hasDirtyPlaceholder
386
389
" PRIMARY KEY(phash)"
387
390
" );" );
388
391
@@ -744,6 +747,16 @@ bool SyncJournalDb::updateMetadataTableStructure()
744
747
commitInternal (QStringLiteral (" update database structure: add contentChecksumTypeId col" ));
745
748
}
746
749
750
+ if (columns.indexOf (" hasDirtyPlaceholder" ) == -1 ) {
751
+ SqlQuery query (_db);
752
+ query.prepare (" ALTER TABLE metadata ADD COLUMN hasDirtyPlaceholder BOOLEAN;" );
753
+ if (!query.exec ()) {
754
+ sqlFail (QStringLiteral (" updateMetadataTableStructure: add hasDirtyPlaceholder column" ), query);
755
+ re = false ;
756
+ }
757
+ commitInternal (QStringLiteral (" update database structure: add hasDirtyPlaceholder col" ));
758
+ }
759
+
747
760
auto uploadInfoColumns = tableColumns (" uploadinfo" );
748
761
if (uploadInfoColumns.isEmpty ())
749
762
return false ;
@@ -881,7 +894,7 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
881
894
qCInfo (lcDb) << " Updating file record for path:" << record._path << " inode:" << record._inode
882
895
<< " modtime:" << record._modtime << " type:" << record._type
883
896
<< " etag:" << record._etag << " fileId:" << record._fileId << " remotePerm:" << record._remotePerm .toString ()
884
- << " fileSize:" << record._fileSize << " checksum:" << record._checksumHeader ;
897
+ << " fileSize:" << record._fileSize << " checksum:" << record._checksumHeader << " hasDirtyPlaceholder: " << record. _hasDirtyPlaceholder ;
885
898
886
899
const qint64 phash = getPHash (record._path );
887
900
if (checkConnect ()) {
@@ -898,8 +911,8 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
898
911
const auto checksumHeader = ChecksumHeader::parseChecksumHeader (record._checksumHeader );
899
912
int contentChecksumTypeId = mapChecksumType (checksumHeader.type ());
900
913
const auto query = _queryManager.get (PreparedSqlQueryManager::SetFileRecordQuery, QByteArrayLiteral (" INSERT OR REPLACE INTO metadata "
901
- " (phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentChecksum, contentChecksumTypeId) "
902
- " VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16);" ),
914
+ " (phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentChecksum, contentChecksumTypeId, hasDirtyPlaceholder ) "
915
+ " VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17 );" ),
903
916
_db);
904
917
if (!query) {
905
918
return query->error ();
@@ -921,6 +934,7 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
921
934
query->bindValue (14 , record._serverHasIgnoredFiles ? 1 : 0 );
922
935
query->bindValue (15 , checksumHeader.checksum ());
923
936
query->bindValue (16 , contentChecksumTypeId);
937
+ query->bindValue (17 , record._hasDirtyPlaceholder );
924
938
925
939
if (!query->exec ()) {
926
940
return query->error ();
@@ -2288,6 +2302,28 @@ SyncJournalDb::~SyncJournalDb()
2288
2302
close ();
2289
2303
}
2290
2304
2305
+ const QVector<SyncJournalFileRecord> SyncJournalDb::getFileRecordsWithDirtyPlaceholders () const
2306
+ {
2307
+ QMutexLocker locker (&_mutex);
2308
+
2309
+ if (OC_ENSURE (isOpen ())) {
2310
+ const auto query = _queryManager.get (PreparedSqlQueryManager::GetFileReocrdsWithDiryPlaceholdersQuery, getFileRecordQueryC + QByteArrayLiteral (" WHERE hasDirtyPlaceholder=TRUE" ), const_cast <SyncJournalDb *>(this )->_db );
2311
+ if (!OC_ENSURE (query)) {
2312
+ return {};
2313
+ }
2314
+ if (!OC_ENSURE (query->exec ())) {
2315
+ return {};
2316
+ }
2317
+ QVector<SyncJournalFileRecord> out;
2318
+ while (query->next ().hasData ) {
2319
+ SyncJournalFileRecord rec;
2320
+ fillFileRecordFromGetQuery (rec, *query);
2321
+ out.append (rec);
2322
+ }
2323
+ return out;
2324
+ }
2325
+ return {};
2326
+ }
2291
2327
2292
2328
bool operator ==(const SyncJournalDb::DownloadInfo &lhs,
2293
2329
const SyncJournalDb::DownloadInfo &rhs)
0 commit comments