diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 0fb13ec13..8674068e3 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -140,8 +140,9 @@ Folder::Folder(const FolderDefinition &definition, Folder::~Folder() { - // TODO cfapi: unregister on wipe()? There should probably be a wipeForRemoval() where this cleanup is appropriate - _vfs->stop(); + // If wipeForRemoval() was called the vfs has already shut down. + if (_vfs) + _vfs->stop(); // Reset then engine first as it will abort and try to access members of the Folder _engine.reset(); @@ -745,20 +746,18 @@ void Folder::slotTerminateSync() } } -// This removes the csync File database -// This is needed to provide a clean startup again in case another -// local folder is synced to the same ownCloud. -void Folder::wipe() +void Folder::wipeForRemoval() { - QString stateDbFile = _engine->journal()->databaseFilePath(); - // Delete files that have been partially downloaded. slotDiscardDownloadProgress(); - //Unregister the socket API so it does not keep the .sync_journal file open + // Unregister the socket API so it does not keep the .sync_journal file open FolderMan::instance()->socketApi()->slotUnregisterPath(alias()); _journal.close(); // close the sync journal + // Remove db and temporaries + QString stateDbFile = _engine->journal()->databaseFilePath(); + QFile file(stateDbFile); if (file.exists()) { if (!file.remove()) { @@ -776,8 +775,9 @@ void Folder::wipe() QFile::remove(stateDbFile + "-wal"); QFile::remove(stateDbFile + "-journal"); - if (canSync()) - FolderMan::instance()->socketApi()->slotRegisterPath(alias()); + _vfs->stop(); + _vfs->unregisterFolder(); + _vfs.reset(nullptr); // warning: folder now in an invalid state } bool Folder::reloadExcludes() diff --git a/src/gui/folder.h b/src/gui/folder.h index ab395b049..4a3c544a2 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -188,8 +188,12 @@ public: /** * This is called when the sync folder definition is removed. Do cleanups here. + * + * It removes the database, among other things. + * + * The folder is not in a valid state afterwards! */ - virtual void wipe(); + virtual void wipeForRemoval(); void setSyncState(SyncResult::Status state); diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 49a3ab286..79be36c3e 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1127,8 +1127,8 @@ void FolderMan::removeFolder(Folder *f) emit scheduleQueueChanged(); } - f->wipe(); f->setSyncPaused(true); + f->wipeForRemoval(); // remove the folder configuration f->removeFromSettings(); @@ -1253,7 +1253,7 @@ void FolderMan::slotWipeFolderForAccount(AccountState *accountState) } // wipe database - f->wipe(); + f->wipeForRemoval(); // wipe data QDir userFolder(f->path());