Просмотр исходного кода

Make sure Folder is deleted from the list and the SyncJournalDB is closed for every folder of the account that has been removed.

Signed-off-by: alex-z <blackslayer4@gmail.com>
alex-z 3 лет назад
Родитель
Сommit
2a529eef3c

+ 3 - 1
src/common/syncjournaldb.cpp

@@ -2425,7 +2425,9 @@ void SyncJournalDb::commitInternal(const QString &context, bool startTrans)
 
 
 SyncJournalDb::~SyncJournalDb()
 SyncJournalDb::~SyncJournalDb()
 {
 {
-    close();
+    if (isOpen()) {
+        close();
+    }
 }
 }
 
 
 
 

+ 0 - 8
src/gui/folder.cpp

@@ -302,14 +302,6 @@ void Folder::setSyncPaused(bool paused)
     emit canSyncChanged();
     emit canSyncChanged();
 }
 }
 
 
-void Folder::onAssociatedAccountRemoved()
-{
-    if (_vfs) {
-        _vfs->stop();
-        _vfs->unregisterFolder();
-    }
-}
-
 void Folder::setSyncState(SyncResult::Status state)
 void Folder::setSyncState(SyncResult::Status state)
 {
 {
     _syncResult.setStatus(state);
     _syncResult.setStatus(state);

+ 0 - 2
src/gui/folder.h

@@ -206,8 +206,6 @@ public:
       */
       */
     virtual void wipeForRemoval();
     virtual void wipeForRemoval();
 
 
-    void onAssociatedAccountRemoved();
-
     void setSyncState(SyncResult::Status state);
     void setSyncState(SyncResult::Status state);
 
 
     void setDirtyNetworkLimits();
     void setDirtyNetworkLimits();

+ 10 - 6
src/gui/folderman.cpp

@@ -945,11 +945,15 @@ void FolderMan::runEtagJobIfPossible(Folder *folder)
 
 
 void FolderMan::slotAccountRemoved(AccountState *accountState)
 void FolderMan::slotAccountRemoved(AccountState *accountState)
 {
 {
+    QVector<Folder *> foldersToRemove;
     for (const auto &folder : qAsConst(_folderMap)) {
     for (const auto &folder : qAsConst(_folderMap)) {
         if (folder->accountState() == accountState) {
         if (folder->accountState() == accountState) {
-            folder->onAssociatedAccountRemoved();
+            foldersToRemove.push_back(folder);
         }
         }
     }
     }
+    for (const auto &folder : qAsConst(foldersToRemove)) {
+        removeFolder(folder);
+    }
 }
 }
 
 
 void FolderMan::slotRemoveFoldersForAccount(AccountState *accountState)
 void FolderMan::slotRemoveFoldersForAccount(AccountState *accountState)
@@ -1663,10 +1667,10 @@ QPair<FolderMan::PathValidityResult, QString> FolderMan::checkPathValidityForNew
 {
 {
     QPair<FolderMan::PathValidityResult, QString> result;
     QPair<FolderMan::PathValidityResult, QString> result;
 
 
-    QString recursiveValidity = checkPathValidityRecursive(path);
+    const auto recursiveValidity = checkPathValidityRecursive(path);
     if (!recursiveValidity.isEmpty()) {
     if (!recursiveValidity.isEmpty()) {
         qCDebug(lcFolderMan) << path << recursiveValidity;
         qCDebug(lcFolderMan) << path << recursiveValidity;
-        result.first = FolderMan::ErrorRecursiveValidity;
+        result.first = FolderMan::PathValidityResult::ErrorRecursiveValidity;
         result.second = recursiveValidity;
         result.second = recursiveValidity;
         return result;
         return result;
     }
     }
@@ -1684,7 +1688,7 @@ QPair<FolderMan::PathValidityResult, QString> FolderMan::checkPathValidityForNew
 
 
         bool differentPaths = QString::compare(folderDir, userDir, cs) != 0;
         bool differentPaths = QString::compare(folderDir, userDir, cs) != 0;
         if (differentPaths && folderDir.startsWith(userDir, cs)) {
         if (differentPaths && folderDir.startsWith(userDir, cs)) {
-            result.first = FolderMan::ErrorContainsFolder;
+            result.first = FolderMan::PathValidityResult::ErrorContainsFolder;
             result.second = tr("The local folder %1 already contains a folder used in a folder sync connection. "
             result.second = tr("The local folder %1 already contains a folder used in a folder sync connection. "
                               "Please pick another one!")
                               "Please pick another one!")
                                 .arg(QDir::toNativeSeparators(path));
                                 .arg(QDir::toNativeSeparators(path));
@@ -1692,7 +1696,7 @@ QPair<FolderMan::PathValidityResult, QString> FolderMan::checkPathValidityForNew
         }
         }
 
 
         if (differentPaths && userDir.startsWith(folderDir, cs)) {
         if (differentPaths && userDir.startsWith(folderDir, cs)) {
-            result.first = FolderMan::ErrorContainedInFolder;
+            result.first = FolderMan::PathValidityResult::ErrorContainedInFolder;
             result.second = tr("The local folder %1 is already contained in a folder used in a folder sync connection. "
             result.second = tr("The local folder %1 is already contained in a folder used in a folder sync connection. "
                       "Please pick another one!")
                       "Please pick another one!")
                 .arg(QDir::toNativeSeparators(path));
                 .arg(QDir::toNativeSeparators(path));
@@ -1708,7 +1712,7 @@ QPair<FolderMan::PathValidityResult, QString> FolderMan::checkPathValidityForNew
             folderUrl.setUserName(user);
             folderUrl.setUserName(user);
 
 
             if (serverUrl == folderUrl) {
             if (serverUrl == folderUrl) {
-                result.first = FolderMan::ErrorNonEmptyFolder;
+                result.first = FolderMan::PathValidityResult::ErrorNonEmptyFolder;
                 result.second = tr("There is already a sync from the server to this local folder. "
                 result.second = tr("There is already a sync from the server to this local folder. "
                           "Please pick another local folder!");
                           "Please pick another local folder!");
                 return result;
                 return result;

+ 1 - 1
src/gui/folderman.h

@@ -63,7 +63,7 @@ class FolderMan : public QObject
 {
 {
     Q_OBJECT
     Q_OBJECT
 public:
 public:
-    enum PathValidityResult {
+    enum class PathValidityResult {
         Valid,
         Valid,
         ErrorRecursiveValidity,
         ErrorRecursiveValidity,
         ErrorContainsFolder,
         ErrorContainsFolder,

+ 1 - 1
src/gui/wizard/owncloudadvancedsetuppage.cpp

@@ -260,7 +260,7 @@ void OwncloudAdvancedSetupPage::updateStatus()
     // check if the local folder exists. If so, and if its not empty, show a warning.
     // check if the local folder exists. If so, and if its not empty, show a warning.
     const auto pathValidityCheckResult = FolderMan::instance()->checkPathValidityForNewFolder(locFolder, serverUrl());
     const auto pathValidityCheckResult = FolderMan::instance()->checkPathValidityForNewFolder(locFolder, serverUrl());
     auto errorStr = pathValidityCheckResult.second;
     auto errorStr = pathValidityCheckResult.second;
-    _localFolderValid = errorStr.isEmpty() || pathValidityCheckResult.first == FolderMan::ErrorNonEmptyFolder;
+    _localFolderValid = errorStr.isEmpty() || pathValidityCheckResult.first == FolderMan::PathValidityResult::ErrorNonEmptyFolder;
 
 
     QString t;
     QString t;
 
 

+ 17 - 17
test/testfolderman.cpp

@@ -65,14 +65,14 @@ private slots:
 
 
 
 
         // those should be allowed
         // those should be allowed
-        // QString FolderMan::checkPathValidityForNewFolder(const QString& path, const QUrl &serverUrl, bool forNewDirectory)
+        // QString FolderMan::checkPathValidityForNewFolder(const QString& path, const QUrl &serverUrl, bool forNewDirectory).second
 
 
         QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/free").second, QString());
         QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/free").second, QString());
         QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/free2/").second, QString());
         QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/free2/").second, QString());
         // Not an existing directory -> Ok
         // Not an existing directory -> Ok
         QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/bliblablu").second, QString());
         QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/bliblablu").second, QString());
         QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/free/bliblablu").second, QString());
         QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/free/bliblablu").second, QString());
-        // QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/bliblablu/some/more"), QString());
+        // QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/bliblablu/some/more").second, QString());
 
 
         // A file -> Error
         // A file -> Error
         QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/file.txt").second.isNull());
         QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/file.txt").second.isNull());
@@ -104,33 +104,33 @@ private slots:
         QVERIFY(QFile::link(dirPath + "/sub/ownCloud1/folder", dirPath + "/link4"));
         QVERIFY(QFile::link(dirPath + "/sub/ownCloud1/folder", dirPath + "/link4"));
 
 
         // Ok
         // Ok
-        QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link1").isNull());
-        QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link2/free").isNull());
+        QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link1").second.isNull());
+        QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link2/free").second.isNull());
 
 
         // Not Ok
         // Not Ok
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link2").isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link2").second.isNull());
 
 
         // link 3 points to an existing sync folder. To make it fail, the account must be the same
         // link 3 points to an existing sync folder. To make it fail, the account must be the same
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3", url2).isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3", url2).second.isNull());
         // while with a different account, this is fine
         // while with a different account, this is fine
-        QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/link3", url3), QString());
+        QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/link3", url3).second, QString());
 
 
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link4").isNull());
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3/folder").isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link4").second.isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3/folder").second.isNull());
 
 
         // test some non existing sub path (error)
         // test some non existing sub path (error)
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1/some/sub/path").isNull());
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/ownCloud2/blublu").isNull());
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1/folder/g/h").isNull());
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3/folder/neu_folder").isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1/some/sub/path").second.isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/ownCloud2/blublu").second.isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/ownCloud1/folder/g/h").second.isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3/folder/neu_folder").second.isNull());
 
 
         // Subfolder of links
         // Subfolder of links
-        QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link1/subfolder").isNull());
-        QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link2/free/subfolder").isNull());
+        QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link1/subfolder").second.isNull());
+        QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + "/link2/free/subfolder").second.isNull());
 
 
         // Should not have the rights
         // Should not have the rights
-        QVERIFY(!folderman->checkPathValidityForNewFolder("/").isNull());
-        QVERIFY(!folderman->checkPathValidityForNewFolder("/usr/bin/somefolder").isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder("/").second.isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder("/usr/bin/somefolder").second.isNull());
 #endif
 #endif
 
 
 #ifdef Q_OS_WIN // drive-letter tests
 #ifdef Q_OS_WIN // drive-letter tests