Skip to content

Commit

Permalink
Rename wipeVirtualFiles -> wipeDehydratedVirtualFiles and document
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Nov 3, 2023
1 parent b32f506 commit 81b9e59
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
27 changes: 18 additions & 9 deletions src/common/vfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,30 @@ Vfs::AvailabilityResult Vfs::availabilityInDb(const QString &folderPath)
return AvailabilityError::NoSuchItem;
}

void Vfs::wipeVirtualFiles()
void Vfs::wipeDehydratedVirtualFiles()
{
if (mode() == Vfs::Mode::Off) {
// there are no placeholders
return;
}
_setupParams->journal->getFilesBelowPath(QByteArray(), [&](const SyncJournalFileRecord &rec) {
if (rec._type != ItemTypeVirtualFile && rec._type != ItemTypeVirtualFileDownload)
// only handle dehydrated files
if (rec._type != ItemTypeVirtualFile && rec._type != ItemTypeVirtualFileDownload) {
return;

qCDebug(lcVfs) << "Removing db record for" << rec._path;
_setupParams->journal->deleteFileRecord(QString::fromUtf8(rec._path));
}
const QString relativePath = QString::fromUtf8(rec._path);
qCDebug(lcVfs) << "Removing db record for dehydrated file" << relativePath;
_setupParams->journal->deleteFileRecord(relativePath);

// If the local file is a dehydrated placeholder, wipe it too.
// Otherwise leave it to allow the next sync to have a new-new conflict.
QString localFile = _setupParams->filesystemPath + QString::fromUtf8(rec._path);
if (QFile::exists(localFile) && isDehydratedPlaceholder(localFile)) {
qCDebug(lcVfs) << "Removing local dehydrated placeholder" << rec._path;
FileSystem::remove(localFile);
const QString absolutePath = _setupParams->filesystemPath + relativePath;
if (QFile::exists(absolutePath)) {
// according to our db this is a dehydrated file, check it to be sure
if (isDehydratedPlaceholder(absolutePath)) {
qCDebug(lcVfs) << "Removing local dehydrated placeholder" << relativePath;
FileSystem::remove(absolutePath);
}
}
});

Expand Down
3 changes: 1 addition & 2 deletions src/common/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ class OCSYNC_EXPORT Vfs : public QObject
*
* Particularly useful when switching off vfs mode or switching to a
* different kind of vfs.
*
*/
void wipeVirtualFiles();
void wipeDehydratedVirtualFiles();

public slots:
/** Update in-sync state based on SyncFileStatusTracker signal.
Expand Down
6 changes: 3 additions & 3 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Folder::Folder(const FolderDefinition &definition,
if (VfsPluginManager::instance().isVfsPluginAvailable(Vfs::WindowsCfApi)) {
if (auto winvfs = VfsPluginManager::instance().createVfsFromPlugin(Vfs::WindowsCfApi)) {
// Wipe the existing suffix files from fs and journal
_vfs->wipeVirtualFiles();
_vfs->wipeDehydratedVirtualFiles();

// Then switch to winvfs mode
_vfs.reset(winvfs.release());
Expand Down Expand Up @@ -771,7 +771,7 @@ void Folder::setVirtualFilesEnabled(bool enabled)
if (newMode != _definition.virtualFilesMode) {
// TODO: Must wait for current sync to finish!
OC_ENFORCE(!isSyncRunning());
_vfs->wipeVirtualFiles();
_vfs->wipeDehydratedVirtualFiles();

_vfs->stop();
_vfs->unregisterFolder();
Expand Down Expand Up @@ -1281,7 +1281,7 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction)
// reset the db upload all local files or download all remote files
FileSystem::setFolderMinimumPermissions(path());
// will remove all dehydrated placeholders
_vfs->wipeVirtualFiles();
_vfs->wipeDehydratedVirtualFiles();
journalDb()->clearFileTable();
}
// if all local files where placeholders, they might be gone after the next sync
Expand Down
2 changes: 1 addition & 1 deletion test/testsyncvirtualfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ private slots:
QVERIFY(fakeFolder.applyLocalModificationsWithoutSync());

// Now wipe the virtuals
fakeFolder.syncEngine().syncOptions()._vfs->wipeVirtualFiles();
fakeFolder.syncEngine().syncOptions()._vfs->wipeDehydratedVirtualFiles();

QVERIFY(!fakeFolder.currentLocalState().find(QStringLiteral("f1") + Theme::instance()->appDotVirtualFileSuffix()));
QVERIFY(!fakeFolder.currentLocalState().find(QStringLiteral("A/a1") + Theme::instance()->appDotVirtualFileSuffix()));
Expand Down

0 comments on commit 81b9e59

Please sign in to comment.