diff --git a/src/csync/csync.h b/src/csync/csync.h index d24915422bba..ca40aa6b4f40 100644 --- a/src/csync/csync.h +++ b/src/csync/csync.h @@ -207,6 +207,7 @@ struct OCSYNC_EXPORT csync_file_stat_s { bool has_ignored_files BITFIELD(1); // Specify that a directory, or child directory contains ignored files. bool is_hidden BITFIELD(1); // Not saved in the DB, only used during discovery for local files. bool isE2eEncrypted BITFIELD(1); + bool is_metadata_missing BITFIELD(1); // Indicates the file has missing metadata, f.ex. the file is not a placeholder in case of vfs. QByteArray path; QByteArray rename_path; @@ -233,6 +234,7 @@ struct OCSYNC_EXPORT csync_file_stat_s { , has_ignored_files(false) , is_hidden(false) , isE2eEncrypted(false) + , is_metadata_missing(false) { } }; diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index e9f05e79f298..8d15e8da3021 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -618,6 +618,8 @@ void Folder::slotWatchedPathChanged(const QString &path, ChangeReason reason) spurious = false; if (*pinState == PinState::OnlineOnly && record.isFile()) spurious = false; + } else { + spurious = false; } } if (spurious) { diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 4cb11c6e5663..7874932ea817 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -473,7 +473,8 @@ void ProcessDirectoryJob::processFile(PathTuple path, << " | type: " << dbEntry._type << "/" << localEntry.type << "/" << (serverEntry.isDirectory ? ItemTypeDirectory : ItemTypeFile) << " | e2ee: " << dbEntry.isE2eEncrypted() << "/" << serverEntry.isE2eEncrypted() << " | e2eeMangledName: " << dbEntry.e2eMangledName() << "/" << serverEntry.e2eMangledName - << " | file lock: " << localFileIsLocked << "//" << serverFileIsLocked; + << " | file lock: " << localFileIsLocked << "//" << serverFileIsLocked + << " | metadata missing: /" << localEntry.isMetadataMissing << '/'; if (localEntry.isValid() && !serverEntry.isValid() @@ -1073,6 +1074,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo( item->_type = ItemTypeVirtualFileDehydration; } else if (!serverModified && (dbEntry._inode != localEntry.inode + || localEntry.isMetadataMissing || _discoveryData->_syncOptions._vfs->needsMetadataUpdate(*item))) { item->_instruction = CSYNC_INSTRUCTION_UPDATE_METADATA; item->_direction = SyncFileItem::Down; diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 6a60fd1c6785..3142a2968a74 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -324,6 +324,7 @@ void DiscoverySingleLocalDirectoryJob::run() { i.isHidden = dirent->is_hidden; i.isSymLink = dirent->type == ItemTypeSoftLink; i.isVirtualFile = dirent->type == ItemTypeVirtualFile || dirent->type == ItemTypeVirtualFileDownload; + i.isMetadataMissing = dirent->is_metadata_missing; i.type = dirent->type; results.push_back(i); } diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index c0da6be82b7b..36b07b874daf 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -101,6 +101,7 @@ struct LocalInfo bool isHidden = false; bool isVirtualFile = false; bool isSymLink = false; + bool isMetadataMissing = false; [[nodiscard]] bool isValid() const { return !name.isNull(); } }; diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.cpp b/src/libsync/vfs/cfapi/cfapiwrapper.cpp index ee729896300a..ac9e90b9ed6c 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.cpp +++ b/src/libsync/vfs/cfapi/cfapiwrapper.cpp @@ -862,3 +862,14 @@ OCC::Result OCC::CfApiWrapper::co return stateResult; } } + +OCC::Result OCC::CfApiWrapper::revertPlaceholder(const QString &path) +{ + const auto result = CfRevertPlaceholder(handleForPath(path).get(), CF_REVERT_FLAG_NONE, nullptr); + if (result != S_OK) { + qCWarning(lcCfApiWrapper) << "Couldn't revert placeholder for" << path << ":" << QString::fromWCharArray(_com_error(result).ErrorMessage()); + return {"Couldn't revert placeholder"}; + } + + return OCC::Vfs::ConvertToPlaceholderResult::Ok; +} diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.h b/src/libsync/vfs/cfapi/cfapiwrapper.h index 10cb51aaa82b..ee5c20216dcb 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.h +++ b/src/libsync/vfs/cfapi/cfapiwrapper.h @@ -97,6 +97,7 @@ NEXTCLOUD_CFAPI_EXPORT Result createPlaceholderInfo(const QString NEXTCLOUD_CFAPI_EXPORT Result updatePlaceholderInfo(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId, const QString &replacesPath = QString()); NEXTCLOUD_CFAPI_EXPORT Result convertToPlaceholder(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId, const QString &replacesPath); NEXTCLOUD_CFAPI_EXPORT Result dehydratePlaceholder(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId); +NEXTCLOUD_CFAPI_EXPORT Result revertPlaceholder(const QString &path); } diff --git a/src/libsync/vfs/cfapi/vfs_cfapi.cpp b/src/libsync/vfs/cfapi/vfs_cfapi.cpp index 931da6f1938e..7763a2fd85a4 100644 --- a/src/libsync/vfs/cfapi/vfs_cfapi.cpp +++ b/src/libsync/vfs/cfapi/vfs_cfapi.cpp @@ -264,17 +264,19 @@ bool VfsCfApi::statTypeVirtualFile(csync_file_stat_t *stat, void *statData) const auto isPinned = (ffd->dwFileAttributes & FILE_ATTRIBUTE_PINNED) != 0; const auto isUnpinned = (ffd->dwFileAttributes & FILE_ATTRIBUTE_UNPINNED) != 0; const auto hasReparsePoint = (ffd->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0; - const auto hasCloudTag = (ffd->dwReserved0 & IO_REPARSE_TAG_CLOUD) != 0; + const auto hasCloudTag = hasReparsePoint && (ffd->dwReserved0 & ~IO_REPARSE_TAG_CLOUD_MASK) == (IO_REPARSE_TAG_CLOUD & ~IO_REPARSE_TAG_CLOUD_MASK); const auto isWindowsShortcut = !isDirectory && FileSystem::isLnkFile(stat->path); const auto isExcludeFile = !isDirectory && FileSystem::isExcludeFile(stat->path); + stat->is_metadata_missing = !hasCloudTag; + // It's a dir with a reparse point due to the placeholder info (hence the cloud tag) // if we don't remove the reparse point flag the discovery will end up thinking // it is a file... let's prevent it if (isDirectory) { - if (hasReparsePoint && hasCloudTag) { + if (hasCloudTag) { ffd->dwFileAttributes &= ~FILE_ATTRIBUTE_REPARSE_POINT; } return false; diff --git a/test/testsynccfapi.cpp b/test/testsynccfapi.cpp index 1576f5330069..cc1a023f5bcd 100644 --- a/test/testsynccfapi.cpp +++ b/test/testsynccfapi.cpp @@ -120,6 +120,45 @@ private slots: QTest::newRow("skip local discovery") << false; } + void testReplaceFileByIdenticalFile() + { + FakeFolder fakeFolder{FileInfo{}}; + auto vfs = setupVfs(fakeFolder); + ItemCompletedSpy completeSpy(fakeFolder); + + // Create a new local (non-placeholder) file + fakeFolder.localModifier().insert("file0"); + fakeFolder.localModifier().insert("file1"); + CopyFile(QString(fakeFolder.localPath() + "file1").toStdWString().data(), QString(fakeFolder.localPath() + "file2").toStdWString().data(), false); + QVERIFY(!vfs->pinState("file0").isValid()); + QVERIFY(!vfs->pinState("file1").isValid()); + QVERIFY(!vfs->pinState("file2").isValid()); + + // Sync the files: files should be converted to placeholder files + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(vfs->pinState("file0").isValid()); + QVERIFY(vfs->pinState("file1").isValid()); + QVERIFY(vfs->pinState("file2").isValid()); + + // Sync again to ensure items are fully synced, otherwise test may succeed due to those pending changes. + QVERIFY(fakeFolder.syncOnce()); + completeSpy.clear(); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(completeSpy.isEmpty()); + + // Replace file1 by identical file2: Windows will convert file1 to a regular (non-placeholder) file again. + CopyFile(QString(fakeFolder.localPath() + "file2").toStdWString().data(), QString(fakeFolder.localPath() + "file1").toStdWString().data(), false); + QVERIFY(vfs->pinState("file0").isValid()); + QVERIFY(!vfs->pinState("file1").isValid()); + QVERIFY(vfs->pinState("file2").isValid()); + + // Sync again: file should be correctly converted to placeholders + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(vfs->pinState("file0").isValid()); + QVERIFY(vfs->pinState("file1").isValid()); + QVERIFY(vfs->pinState("file2").isValid()); + } + void testReplaceOnlineOnlyFile() { FakeFolder fakeFolder{FileInfo{}};