From 30c343f238758e9ec5ae0edb9951eea8cbdbea51 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 4 Dec 2025 14:54:38 +0100 Subject: [PATCH] Remove OC10SyncRoot Also simplify the path validity checks. --- src/gui/folderman.cpp | 125 ++++++++--------- src/gui/folderman.h | 21 ++- src/gui/folderwizard/folderwizard.cpp | 3 +- .../folderwizard/folderwizardlocalpath.cpp | 2 +- .../advancedsettingspagecontroller.cpp | 2 +- test/testfolderman.cpp | 131 ++++++++++-------- 6 files changed, 146 insertions(+), 138 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 7508a0aab5f..dc4d59c60a3 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -912,29 +912,40 @@ static QString canonicalPath(const QString &path) static QString checkPathForSyncRootMarkingRecursive(const QString &path, FolderMan::NewFolderType folderType, const QUuid &accountUuid) { + // First do basic checks if this path is usable + const QFileInfo selectedPathInfo(path); + if (!selectedPathInfo.isDir()) { + return FolderMan::tr("The selected path is not a folder."); + } + + if (numberOfSyncJournals(selectedPathInfo.filePath()) != 0) { + return FolderMan::tr("The folder %1 is used in a folder sync connection.").arg(QDir::toNativeSeparators(selectedPathInfo.filePath())); + } + + // Check for sync root markings in this folder std::pair existingTags = Utility::getDirectorySyncRootMarkings(path); if (!existingTags.first.isEmpty()) { if (existingTags.first != Theme::instance()->orgDomainName()) { // another application uses this as spaces root folder - return FolderMan::tr("Folder '%1' is already in use by application %2!").arg(path, existingTags.first); + return FolderMan::tr("Folder '%1' is already in use by application %2.").arg(path, existingTags.first); } // Looks good, it's our app, let's check the account tag: switch (folderType) { case FolderMan::NewFolderType::SpacesFolder: if (existingTags.second == accountUuid) { - // Nice, that's what we like, the sync root for our account in our app. No error. + // Nice, that's what we like, the sync root for our account in our app. No error, and we don't need to check the parent folders. return {}; } [[fallthrough]]; - case FolderMan::NewFolderType::OC10SyncRoot: - [[fallthrough]]; case FolderMan::NewFolderType::SpacesSyncRoot: // It's our application but we don't want to create a spaces folder, so it must be another space root return FolderMan::tr("Folder '%1' is already in use by another account.").arg(path); } } + // This folder is ok, but check the parent folders if they are used + QString parent = QFileInfo(path).path(); if (parent == path) { // root dir, stop recursing return {}; @@ -943,51 +954,7 @@ static QString checkPathForSyncRootMarkingRecursive(const QString &path, FolderM return checkPathForSyncRootMarkingRecursive(parent, folderType, accountUuid); } -QString FolderMan::checkPathValidityRecursive(const QString &path, FolderMan::NewFolderType folderType, const QUuid &accountUuid) -{ - if (path.isEmpty()) { - return FolderMan::tr("No valid folder selected!"); - } - -#ifdef Q_OS_WIN - Utility::NtfsPermissionLookupRAII ntfs_perm; -#endif - - auto pathLengthCheck = Folder::checkPathLength(path); - if (!pathLengthCheck) { - return pathLengthCheck.error(); - } - - const QFileInfo selectedPathInfo(path); - if (!selectedPathInfo.exists()) { - const QString parentPath = selectedPathInfo.path(); - if (parentPath != path) { - return checkPathValidityRecursive(parentPath, folderType, accountUuid); - } - return FolderMan::tr("The selected path does not exist!"); - } - - if (numberOfSyncJournals(selectedPathInfo.filePath()) != 0) { - return FolderMan::tr("The folder %1 is used in a folder sync connection!").arg(QDir::toNativeSeparators(selectedPathInfo.filePath())); - } - - // At this point we know there is no syncdb in the parent hierarchy, check for spaces sync root. - - if (!selectedPathInfo.isDir()) { - return FolderMan::tr("The selected path is not a folder!"); - } - - if (!selectedPathInfo.isWritable()) { - return FolderMan::tr("You have no permission to write to the selected folder!"); - } - - return checkPathForSyncRootMarkingRecursive(path, folderType, accountUuid); -} - /* - * OC10 folder: - * - sync root not in syncdb folder - * - sync root not in spaces root * with spaces: * - spaces sync root not in syncdb folder * - spaces sync root not in another spaces sync root @@ -996,37 +963,67 @@ QString FolderMan::checkPathValidityRecursive(const QString &path, FolderMan::Ne * - space *can* be in sync root * - space not in spaces sync root of other account (check with account uuid) */ -QString FolderMan::checkPathValidityForNewFolder(const QString &path, NewFolderType folderType, const QUuid &accountUuid) const +QString FolderMan::checkPathValidity(const QString &path, NewFolderType folderType, const QUuid &accountUuid) { - // check if the local directory isn't used yet in another ownCloud sync + // Do checks against existing folders. This catches cases where: + // - the user deleted a folder from the filesystem, but there is still a folder sync connection in the configuration + // - check if this folder contains other folders for spaces + // If so, error out. const auto cs = Utility::fsCaseSensitivity(); - const QString userDir = QDir::cleanPath(canonicalPath(path)) + QLatin1Char('/'); - for (auto f : folders()) { + for (auto f : FolderMan::instance()->folders()) { const QString folderDir = QDir::cleanPath(canonicalPath(f->path())) + QLatin1Char('/'); - if (QString::compare(folderDir, userDir, cs) == 0) { - return tr("There is already a sync from the server to this local folder. " - "Please pick another local folder!"); + return tr("There is already a sync from the server to this local folder."); } if (FileSystem::isChildPathOf(folderDir, userDir)) { - return tr("The local folder %1 already contains a folder used in a folder sync connection. " - "Please pick another local folder!") + return tr("The local folder %1 already contains a folder used in a folder sync connection.") .arg(QDir::toNativeSeparators(path)); } if (FileSystem::isChildPathOf(userDir, folderDir)) { - return tr("The local folder %1 is already contained in a folder used in a folder sync connection. " - "Please pick another local folder!") + return tr("The local folder %1 is already contained in a folder used in a folder sync connection.") .arg(QDir::toNativeSeparators(path)); } } - const auto result = checkPathValidityRecursive(path, folderType, accountUuid); - if (!result.isEmpty()) { - return tr("%1 Please pick another local folder!").arg(result); + // Now run filesystem based checks + return checkPathValidityRecursive(path, folderType, accountUuid); +} + +QString FolderMan::checkPathValidityRecursive(const QString &path, NewFolderType folderType, const QUuid &accountUuid) +{ + if (path.isEmpty()) { + return FolderMan::tr("No valid folder selected."); } - return {}; + +#ifdef Q_OS_WIN + Utility::NtfsPermissionLookupRAII ntfs_perm; +#endif + + auto pathLengthCheck = Folder::checkPathLength(path); + if (!pathLengthCheck) { + return pathLengthCheck.error(); + } + + // If this is a new folder, recurse up to the first parent that exists, to see if we can use that to create a new folder + const QFileInfo selectedPathInfo(path); + if (!selectedPathInfo.exists()) { + const QString parentPath = selectedPathInfo.path(); + if (parentPath != path) { + return checkPathValidityRecursive(parentPath, folderType, accountUuid); + } + return FolderMan::tr("The selected path does not exist."); + } + + // At this point we have an existing folder, so check if we can create files/folders here. + // Note: we don't need to write to any parent, so we don't need to check writablility when traversing the parents. + if (!selectedPathInfo.isWritable()) { + return FolderMan::tr("You have no permission to write to the selected folder."); + } + + // Now check if none of the parents is already used. + return checkPathForSyncRootMarkingRecursive(canonicalPath(path), folderType, accountUuid); } QString FolderMan::findGoodPathForNewSyncFolder( @@ -1050,7 +1047,7 @@ QString FolderMan::findGoodPathForNewSyncFolder( { QString folder = normalisedPath; for (int attempt = 2; attempt <= 100; ++attempt) { - if (!QFileInfo::exists(folder) && FolderMan::instance()->checkPathValidityForNewFolder(folder, folderType, accountUuid).isEmpty()) { + if (!QFileInfo::exists(folder) && checkPathValidity(folder, folderType, accountUuid).isEmpty()) { return canonicalPath(folder); } folder = normalisedPath + QStringLiteral(" (%1)").arg(attempt); diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 518a3df967e..12a7a99c3e0 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -85,7 +85,6 @@ class OWNCLOUDGUI_EXPORT FolderMan : public QObject * Or in case of a space folder, that if the new folder is in a Space sync root, it is the sync root of the same account. */ enum class NewFolderType { - OC10SyncRoot, // todo: #43 SpacesSyncRoot, SpacesFolder, }; @@ -130,8 +129,13 @@ class OWNCLOUDGUI_EXPORT FolderMan : public QObject static QString suggestSyncFolder(NewFolderType folderType, const QUuid &accountUuid); - - static QString checkPathValidityRecursive(const QString &path, FolderMan::NewFolderType folderType, const QUuid &accountUuid); + /** + * @brief Check a path for validity. + * + * We do not allow putting a folder inside another folder that is already syncing to a server. We also disallow a space to be put into the default sync root + * of another (possibly branded) client, nor in the defaut sync root of another account in our own client. + */ + static QString checkPathValidity(const QString &path, NewFolderType folderType, const QUuid &accountUuid); static std::unique_ptr createInstance(); @@ -215,14 +219,6 @@ class OWNCLOUDGUI_EXPORT FolderMan : public QObject SocketApi *socketApi(); - /** - * Check if @a path is a valid path for a new folder considering the already sync'ed items. - * Make sure that this folder, or any subfolder is not sync'ed already. - * - * @returns an empty string if it is allowed, or an error if it is not allowed - */ - QString checkPathValidityForNewFolder(const QString &path, NewFolderType folderType, const QUuid &accountUuid) const; - /** * Attempts to find a non-existing, acceptable path for creating a new sync folder. * @@ -457,6 +453,9 @@ private Q_SLOTS: // pair this with _socketApi->slotUnregisterPath(folder); void registerFolderWithSocketApi(Folder *folder); + // Helper for `checkPathValidity` + static QString checkPathValidityRecursive(const QString &path, NewFolderType folderType, const QUuid &accountUuid); + QString _folderConfigPath; bool _ignoreHiddenFiles = true; diff --git a/src/gui/folderwizard/folderwizard.cpp b/src/gui/folderwizard/folderwizard.cpp index 238ae100191..bec11fc95f6 100644 --- a/src/gui/folderwizard/folderwizard.cpp +++ b/src/gui/folderwizard/folderwizard.cpp @@ -59,13 +59,12 @@ QString FolderWizardPrivate::formatWarnings(const QStringList &warnings, bool is return ret; } -// todo: #43 QString FolderWizardPrivate::defaultSyncRoot() const { // this should never happen when we have set up the account using spaces - there is ALWAYS a default root when spaces are in play // and they are always in play so this check is bogus. todo: #43 if (!_account->hasDefaultSyncRoot()) { - const auto folderType = FolderMan::NewFolderType::SpacesSyncRoot; // todo: #43 : FolderMan::NewFolderType::OC10SyncRoot; + const auto folderType = FolderMan::NewFolderType::SpacesSyncRoot; return FolderMan::suggestSyncFolder(folderType, _account->uuid()); } else { return _account->defaultSyncRoot(); diff --git a/src/gui/folderwizard/folderwizardlocalpath.cpp b/src/gui/folderwizard/folderwizardlocalpath.cpp index ef27ab9d6f5..c47b5df0e4f 100644 --- a/src/gui/folderwizard/folderwizardlocalpath.cpp +++ b/src/gui/folderwizard/folderwizardlocalpath.cpp @@ -65,7 +65,7 @@ bool FolderWizardLocalPath::isComplete() const { auto folderType = FolderMan::NewFolderType::SpacesFolder; auto accountUuid = folderWizardPrivate()->uuid(); - QString errorStr = FolderMan::instance()->checkPathValidityForNewFolder(localPath(), folderType, accountUuid); + QString errorStr = FolderMan::checkPathValidity(localPath(), folderType, accountUuid); bool isOk = errorStr.isEmpty(); QStringList warnStrings; diff --git a/src/gui/newaccountwizard/advancedsettingspagecontroller.cpp b/src/gui/newaccountwizard/advancedsettingspagecontroller.cpp index 974acca2a59..19efc6b1aec 100644 --- a/src/gui/newaccountwizard/advancedsettingspagecontroller.cpp +++ b/src/gui/newaccountwizard/advancedsettingspagecontroller.cpp @@ -226,7 +226,7 @@ bool AdvancedSettingsPageController::validateSyncRoot(const QString &rootPath) return false; } - QString invalidPathErrorMessage = FolderMan::checkPathValidityRecursive(rootPath, FolderMan::NewFolderType::SpacesSyncRoot, {}); + QString invalidPathErrorMessage = FolderMan::checkPathValidity(rootPath, FolderMan::NewFolderType::SpacesSyncRoot, {}); if (!invalidPathErrorMessage.isEmpty()) { _errorField->setText(errorMessageTemplate.arg(rootPath, invalidPathErrorMessage)); return false; diff --git a/test/testfolderman.cpp b/test/testfolderman.cpp index c3d3257b8f8..4fb92f6cc5c 100644 --- a/test/testfolderman.cpp +++ b/test/testfolderman.cpp @@ -31,6 +31,9 @@ class TestFolderMan: public QObject { Q_OBJECT private Q_SLOTS: + /* + * Note: this is only meant for folders/spaces, not `SpacesSyncRoot` testing! That is done in `testSpacesSyncRootAndFolderCreation`. + */ void testCheckPathValidityForNewFolder() { #ifdef Q_OS_WIN @@ -59,31 +62,28 @@ private Q_SLOTS: QVERIFY(folderman->addFolder( newAccountState.get(), TestUtils::createDummyFolderDefinition(newAccountState->account(), dirPath + QStringLiteral("/ownCloud2")))); - // todo! #43 We don't support OC10 now so using this OC10SyncRoot as type is way off base for the current impls - const auto type = FolderMan::NewFolderType::OC10SyncRoot; - // the uuid actually needs to be associated with a real account + const auto type = FolderMan::NewFolderType::SpacesFolder; const QUuid uuid = newAccountState->account()->uuid(); // 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) - QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/free"), type, uuid), QString()); - QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/free2/"), type, uuid), QString()); + QCOMPARE(FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/free"), type, uuid), QString()); + QCOMPARE(FolderMan::checkPathValidity(dirPath + QStringLiteral("/free2/"), type, uuid), QString()); // Not an existing directory -> Ok - QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/bliblablu"), type, uuid), QString()); - QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/free/bliblablu"), type, uuid), QString()); - // QCOMPARE(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/bliblablu/some/more")), QString()); + QCOMPARE(FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/bliblablu"), type, uuid), QString()); + QCOMPARE(FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/free/bliblablu"), type, uuid), QString()); // A file -> Error - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/file.txt"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/file.txt"), type, uuid).isNull()); // The following both fail because they refer to the same account - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/ownCloud1"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/ownCloud2/"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/ownCloud1"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/ownCloud2/"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath, type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/ownCloud1/folder"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/ownCloud1/folder/f"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath, type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/ownCloud1/folder"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/ownCloud1/folder/f"), type, uuid).isNull()); #ifndef Q_OS_WIN // no links on windows, no permissions // make a bunch of links @@ -93,78 +93,81 @@ private Q_SLOTS: QVERIFY(QFile::link(dirPath + QStringLiteral("/sub/ownCloud1/folder"), dirPath + QStringLiteral("/link4"))); // Ok - QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link1"), type, uuid).isNull()); - QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link2/free"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(dirPath + QStringLiteral("/link1"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(dirPath + QStringLiteral("/link2/free"), type, uuid).isNull()); // Not Ok - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link2"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/link2"), type, uuid).isNull()); // link 3 points to an existing sync folder. To make it fail, the account must be the same - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link3"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/link3"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link4"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link3/folder"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/link4"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/link3/folder"), type, uuid).isNull()); // test some non existing sub path (error) - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/ownCloud1/some/sub/path"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/ownCloud2/blublu"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/sub/ownCloud1/folder/g/h"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link3/folder/neu_folder"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/ownCloud1/some/sub/path"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/ownCloud2/blublu"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/sub/ownCloud1/folder/g/h"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/link3/folder/neu_folder"), type, uuid).isNull()); // Subfolder of links - QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link1/subfolder"), type, uuid).isNull()); - QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/link2/free/subfolder"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(dirPath + QStringLiteral("/link1/subfolder"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(dirPath + QStringLiteral("/link2/free/subfolder"), type, uuid).isNull()); if (getuid() != 0) { // Should not have the rights - QVERIFY(!folderman->checkPathValidityForNewFolder(QStringLiteral("/"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(QStringLiteral("/usr/bin/somefolder"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(QStringLiteral("/"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(QStringLiteral("/usr/bin/somefolder"), type, uuid).isNull()); } #endif if (Utility::isWindows()) { // drive-letter tests - if (!QFileInfo(QStringLiteral("v:/")).exists()) { - QVERIFY(!folderman->checkPathValidityForNewFolder(QStringLiteral("v:"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(QStringLiteral("v:/"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(QStringLiteral("v:/foo"), type, uuid).isNull()); + if (!QFileInfo::exists("v:/")) { + QVERIFY(!FolderMan::checkPathValidity(QStringLiteral("v:"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(QStringLiteral("v:/"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(QStringLiteral("v:/foo"), type, uuid).isNull()); } if (QFileInfo(QStringLiteral("c:/")).isWritable()) { - QVERIFY(folderman->checkPathValidityForNewFolder(QStringLiteral("c:"), type, uuid).isNull()); - QVERIFY(folderman->checkPathValidityForNewFolder(QStringLiteral("c:/"), type, uuid).isNull()); - QVERIFY(folderman->checkPathValidityForNewFolder(QStringLiteral("c:/foo"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(QStringLiteral("c:"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(QStringLiteral("c:/"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(QStringLiteral("c:/foo"), type, uuid).isNull()); } } // Invalid paths - QVERIFY(!folderman->checkPathValidityForNewFolder({}, type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity({}, type, uuid).isNull()); // REMOVE ownCloud2 from the filesystem, but keep a folder sync'ed to it. QDir(dirPath + QStringLiteral("/ownCloud2/")).removeRecursively(); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/ownCloud2/blublu"), type, uuid).isNull()); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/ownCloud2/sub/subsub/sub"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/ownCloud2/blublu"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/ownCloud2/sub/subsub/sub"), type, uuid).isNull()); { // check for rejection of a directory with `.sync_*.db` QVERIFY(dir2.mkpath(QStringLiteral("db-check1"))); - QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/db-check1"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(dirPath + QStringLiteral("/db-check1"), type, uuid).isNull()); QFile f(dirPath + QStringLiteral("/db-check1/.sync_something.db")); QVERIFY(f.open(QFile::Truncate | QFile::WriteOnly)); f.close(); QVERIFY(QFileInfo::exists(dirPath + QStringLiteral("/db-check1/.sync_something.db"))); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/db-check1"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/db-check1"), type, uuid).isNull()); } { // check for rejection of a directory with `._sync_*.db` QVERIFY(dir2.mkpath(QStringLiteral("db-check2"))); - QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/db-check2"), type, uuid).isNull()); + QVERIFY(FolderMan::checkPathValidity(dirPath + QStringLiteral("/db-check2"), type, uuid).isNull()); QFile f(dirPath + QStringLiteral("/db-check2/._sync_something.db")); QVERIFY(f.open(QFile::Truncate | QFile::WriteOnly)); f.close(); QVERIFY(QFileInfo::exists(dirPath + QStringLiteral("/db-check2/._sync_something.db"))); - QVERIFY(!folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/db-check2"), type, uuid).isNull()); + QVERIFY(!FolderMan::checkPathValidity(dirPath + QStringLiteral("/db-check2"), type, uuid).isNull()); } } + /* + * Note: this is only meant for folders/spaces, not `SpacesSyncRoot` testing! That is done in `testSpacesSyncRootAndFolderCreation`. + */ void testFindGoodPathForNewSyncFolder() { // SETUP @@ -172,7 +175,10 @@ private Q_SLOTS: auto dir = TestUtils::createTempDir(); QVERIFY(dir.isValid()); QDir dir2(dir.path()); + + // Folder in config and on disk: QVERIFY(dir2.mkpath(QStringLiteral("sub/ownCloud1/folder/f"))); + // Folders only on disk, not in configuration: QVERIFY(dir2.mkpath(QStringLiteral("ownCloud"))); QVERIFY(dir2.mkpath(QStringLiteral("ownCloud2"))); QVERIFY(dir2.mkpath(QStringLiteral("ownCloud2/foo"))); @@ -183,14 +189,16 @@ private Q_SLOTS: auto newAccountState = createDummyAccount(); FolderMan *folderman = TestUtils::folderMan(); + // Add folder that is in the configuration, AND on disk: QVERIFY(folderman->addFolder( newAccountState.get(), TestUtils::createDummyFolderDefinition(newAccountState->account(), dirPath + QStringLiteral("/sub/ownCloud/")))); + // Add folder that is in the configuration, not on disk: QVERIFY(folderman->addFolder( newAccountState.get(), TestUtils::createDummyFolderDefinition(newAccountState->account(), dirPath + QStringLiteral("/ownCloud (2)/")))); // TEST - const auto folderType = FolderMan::NewFolderType::OC10SyncRoot; - const auto uuid = QUuid::createUuid(); + const auto folderType = FolderMan::NewFolderType::SpacesFolder; + const auto uuid = newAccountState->account()->uuid(); QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath, QStringLiteral("oc"), folderType, uuid), dirPath + QStringLiteral("/oc")); QCOMPARE(folderman->findGoodPathForNewSyncFolder(dirPath, QStringLiteral("ownCloud"), folderType, uuid), dirPath + QStringLiteral("/ownCloud (3)")); @@ -223,12 +231,14 @@ private Q_SLOTS: void testSpacesSyncRootAndFolderCreation() { + const QString someDeepPath = "/Some/Deep/Path"; + auto dir = TestUtils::createTempDir(); QVERIFY(dir.isValid()); QDir dir2(dir.path()); // Create a sync root for another account - QVERIFY(dir2.mkpath(QStringLiteral("AnotherSpacesSyncRoot"))); + QVERIFY(dir2.mkpath(QStringLiteral("AnotherSpacesSyncRoot") + someDeepPath)); const auto anotherUuid = QUuid::createUuid(); Utility::markDirectoryAsSyncRoot(dir2.filePath(QStringLiteral("AnotherSpacesSyncRoot")), anotherUuid); @@ -239,27 +249,30 @@ private Q_SLOTS: const auto ourUuid = QUuid::createUuid(); // Spaces Sync Root in another Spaces Sync Root should fail - QVERIFY(!folderman - ->checkPathValidityForNewFolder( - dirPath + QStringLiteral("/AnotherSpacesSyncRoot/OurSpacesSyncRoot"), FolderMan::NewFolderType::SpacesSyncRoot, ourUuid) - .isNull()); + QVERIFY(!FolderMan::checkPathValidity( + dirPath + QStringLiteral("/AnotherSpacesSyncRoot/OurSpacesSyncRoot"), FolderMan::NewFolderType::SpacesSyncRoot, ourUuid) + .isNull()); + // Also deep inside + QVERIFY(!FolderMan::checkPathValidity( + dirPath + QStringLiteral("/AnotherSpacesSyncRoot") + someDeepPath + "/OurSpacesSyncRoot", FolderMan::NewFolderType::SpacesSyncRoot, ourUuid) + .isNull()); // Spaces Sync Root one level up should be fine - QVERIFY(folderman->checkPathValidityForNewFolder(dirPath + QStringLiteral("/OurSpacesSyncRoot"), FolderMan::NewFolderType::SpacesSyncRoot, ourUuid) - .isNull()); + QVERIFY(FolderMan::checkPathValidity(dirPath + QStringLiteral("/OurSpacesSyncRoot"), FolderMan::NewFolderType::SpacesSyncRoot, ourUuid).isNull()); // Create the sync root so we can test Spaces Folder creation below QVERIFY(dir2.mkpath(QStringLiteral("OurSpacesSyncRoot"))); Utility::markDirectoryAsSyncRoot(dir2.filePath(QStringLiteral("OurSpacesSyncRoot")), ourUuid); // A folder for a Space in a sync root for another account should fail - QVERIFY(!folderman - ->checkPathValidityForNewFolder( - dirPath + QStringLiteral("/AnotherSpacesSyncRoot/OurSpacesFolder"), FolderMan::NewFolderType::SpacesFolder, ourUuid) - .isNull()); - // But in our sync root that should just be fine QVERIFY( - folderman - ->checkPathValidityForNewFolder(dirPath + QStringLiteral("/OurSpacesSyncRoot/OurSpacesFolder"), FolderMan::NewFolderType::SpacesFolder, ourUuid) + !FolderMan::checkPathValidity(dirPath + QStringLiteral("/AnotherSpacesSyncRoot/OurSpacesFolder"), FolderMan::NewFolderType::SpacesFolder, ourUuid) + .isNull()); + // Also deep inside + QVERIFY(!FolderMan::checkPathValidity( + dirPath + QStringLiteral("/AnotherSpacesSyncRoot") + someDeepPath + "/OurSpacesFolder", FolderMan::NewFolderType::SpacesFolder, ourUuid) + .isNull()); + // But in our sync root that should just be fine + QVERIFY(FolderMan::checkPathValidity(dirPath + QStringLiteral("/OurSpacesSyncRoot/OurSpacesFolder"), FolderMan::NewFolderType::SpacesFolder, ourUuid) .isNull()); } };