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>
This commit is contained in:
alex-z 2022-09-08 14:21:30 +03:00 коммит произвёл Matthieu Gallien
Родитель f0b9ecd747
Коммит 2a529eef3c
7 изменённых файлов: 32 добавлений и 36 удалений

Просмотреть файл

@ -2425,8 +2425,10 @@ void SyncJournalDb::commitInternal(const QString &context, bool startTrans)
SyncJournalDb::~SyncJournalDb()
{
if (isOpen()) {
close();
}
}
bool operator==(const SyncJournalDb::DownloadInfo &lhs,

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -945,11 +945,15 @@ void FolderMan::runEtagJobIfPossible(Folder *folder)
void FolderMan::slotAccountRemoved(AccountState *accountState)
{
QVector<Folder *> foldersToRemove;
for (const auto &folder : qAsConst(_folderMap)) {
if (folder->accountState() == accountState) {
folder->onAssociatedAccountRemoved();
foldersToRemove.push_back(folder);
}
}
for (const auto &folder : qAsConst(foldersToRemove)) {
removeFolder(folder);
}
}
void FolderMan::slotRemoveFoldersForAccount(AccountState *accountState)
@ -1663,10 +1667,10 @@ QPair<FolderMan::PathValidityResult, QString> FolderMan::checkPathValidityForNew
{
QPair<FolderMan::PathValidityResult, QString> result;
QString recursiveValidity = checkPathValidityRecursive(path);
const auto recursiveValidity = checkPathValidityRecursive(path);
if (!recursiveValidity.isEmpty()) {
qCDebug(lcFolderMan) << path << recursiveValidity;
result.first = FolderMan::ErrorRecursiveValidity;
result.first = FolderMan::PathValidityResult::ErrorRecursiveValidity;
result.second = recursiveValidity;
return result;
}
@ -1684,7 +1688,7 @@ QPair<FolderMan::PathValidityResult, QString> FolderMan::checkPathValidityForNew
bool differentPaths = QString::compare(folderDir, userDir, cs) != 0;
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. "
"Please pick another one!")
.arg(QDir::toNativeSeparators(path));
@ -1692,7 +1696,7 @@ QPair<FolderMan::PathValidityResult, QString> FolderMan::checkPathValidityForNew
}
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. "
"Please pick another one!")
.arg(QDir::toNativeSeparators(path));
@ -1708,7 +1712,7 @@ QPair<FolderMan::PathValidityResult, QString> FolderMan::checkPathValidityForNew
folderUrl.setUserName(user);
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. "
"Please pick another local folder!");
return result;

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -65,14 +65,14 @@ private slots:
// 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 + "/free2/").second, QString());
// Not an existing directory -> Ok
QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + "/sub/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
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/sub/file.txt").second.isNull());
@ -104,33 +104,33 @@ private slots:
QVERIFY(QFile::link(dirPath + "/sub/ownCloud1/folder", dirPath + "/link4"));
// 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
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
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3", url2).isNull());
QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + "/link3", url2).second.isNull());
// 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)
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
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
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
#ifdef Q_OS_WIN // drive-letter tests