From 406bad8ab49a4eb65b0d2f7984e6e1338cb29f81 Mon Sep 17 00:00:00 2001 From: alex-z Date: Tue, 17 Oct 2023 17:37:25 +0200 Subject: [PATCH] Enforce virtual file type when it is falsely marked as non-virtual. Added more logs for scenarios when virtual placeholder gets marked as non-virtual. Signed-off-by: alex-z --- src/libsync/discovery.cpp | 9 +++++++-- src/libsync/syncfileitem.cpp | 4 +++- src/libsync/vfs/cfapi/vfs_cfapi.cpp | 13 ++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 87088efde6a48..f11b9ab907fef 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -498,6 +498,7 @@ void ProcessDirectoryJob::processFile(PathTuple path, if (dbEntry._modtime == localEntry.modtime && dbEntry._type == ItemTypeVirtualFile && localEntry.type == ItemTypeFile) { item->_type = ItemTypeFile; + qCInfo(lcDisco) << "Changing item type from virtual to normal file" << item->_file; } // The item shall only have this type if the db request for the virtual download @@ -507,8 +508,10 @@ void ProcessDirectoryJob::processFile(PathTuple path, item->_type = ItemTypeVirtualFile; // Similarly db entries with a dehydration request denote a regular file // until the request is processed. - if (item->_type == ItemTypeVirtualFileDehydration) + if (item->_type == ItemTypeVirtualFileDehydration) { item->_type = ItemTypeFile; + qCInfo(lcDisco) << "Changing item type from virtual to normal file" << item->_file; + } // VFS suffixed files on the server are ignored if (isVfsWithSuffix()) { @@ -1441,8 +1444,10 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo( // but it complicates handling a lot and will happen rarely. if (item->_type == ItemTypeVirtualFileDownload) item->_type = ItemTypeVirtualFile; - if (item->_type == ItemTypeVirtualFileDehydration) + if (item->_type == ItemTypeVirtualFileDehydration) { item->_type = ItemTypeFile; + qCInfo(lcDisco) << "Changing item type from virtual to normal file" << item->_file; + } qCInfo(lcDisco) << "Rename detected (up) " << item->_file << " -> " << item->_renameTarget; }; diff --git a/src/libsync/syncfileitem.cpp b/src/libsync/syncfileitem.cpp index 42d8843e99c55..29be0b35f26ff 100644 --- a/src/libsync/syncfileitem.cpp +++ b/src/libsync/syncfileitem.cpp @@ -81,8 +81,10 @@ SyncJournalFileRecord SyncFileItem::toSyncJournalFileRecordWithInode(const QStri // Some types should never be written to the database when propagation completes rec._type = _type; - if (rec._type == ItemTypeVirtualFileDownload) + if (rec._type == ItemTypeVirtualFileDownload) { rec._type = ItemTypeFile; + qCInfo(lcFileItem) << "Changing item type from ItemTypeVirtualFileDownload to normal file to avoid wrong record type in database" << rec._path; + } if (rec._type == ItemTypeVirtualFileDehydration) rec._type = ItemTypeVirtualFile; diff --git a/src/libsync/vfs/cfapi/vfs_cfapi.cpp b/src/libsync/vfs/cfapi/vfs_cfapi.cpp index d622913fd6d1a..595cc52159185 100644 --- a/src/libsync/vfs/cfapi/vfs_cfapi.cpp +++ b/src/libsync/vfs/cfapi/vfs_cfapi.cpp @@ -396,8 +396,19 @@ void VfsCfApi::requestHydration(const QString &requestId, const QString &path) return; } + bool isNotVirtualFileFailure = false; if (!record.isVirtualFile()) { - qCInfo(lcCfApi) << "Couldn't hydrate, the file is not virtual"; + if (isDehydratedPlaceholder(path)) { + qCWarning(lcCfApi) << "Hydration requested for a placeholder file not marked as virtual in local DB. Attempting to fix it..."; + record._type = ItemTypeVirtualFileDownload; + isNotVirtualFileFailure = !journal->setFileRecord(record); + } else { + isNotVirtualFileFailure = true; + } + } + + if (isNotVirtualFileFailure) { + qCWarning(lcCfApi) << "Couldn't hydrate, the file is not virtual"; emit hydrationRequestFailed(requestId); return; }