Vfs: Call unregisterFolder() when folder is removed
authorChristian Kamm <mail@ckamm.de>
Fri, 25 Jan 2019 12:16:32 +0000 (13:16 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:39 +0000 (10:58 +0100)
src/gui/folder.cpp
src/gui/folder.h
src/gui/folderman.cpp

index 0fb13ec1301aaa4160763a13500e970129f0553e..8674068e329869558fe1a4c0f014fe68d4ae1b41 100644 (file)
@@ -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()
index ab395b04985ea569415871892155ef6ef1bb48f4..4a3c544a2a9e3fa221442611bba51a92a5c6cb21 100644 (file)
@@ -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);
 
index 49a3ab286819d07b566bacccdd696231ba2f03d1..79be36c3ebc1688dda38cb66d68e72dd5815aeeb 100644 (file)
@@ -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());