Skip to content

Commit

Permalink
Enforce virtual file type when it is falsely marked as non-virtual. A…
Browse files Browse the repository at this point in the history
…dded more logs for scenarios when virtual placeholder gets marked as non-virtual.

Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Oct 23, 2023
1 parent b362187 commit 25ef0a9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
};
Expand Down
4 changes: 3 additions & 1 deletion src/libsync/syncfileitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 12 additions & 1 deletion src/libsync/vfs/cfapi/vfs_cfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 25ef0a9

Please sign in to comment.