@@ -720,22 +720,41 @@ static QString canonicalPath(const QString &path)
720
720
return selFile.canonicalFilePath ();
721
721
}
722
722
723
- static QString checkPathForSyncRootMarkingRecursive (const QString &path)
724
- {
725
- auto existingTag = Utility::getDirectorySyncRootMarking (path);
726
- if (!existingTag.isEmpty ()) {
727
- return FolderMan::tr (" Folder '%1' is already in use by application %2!" ).arg (path, existingTag);
723
+ static QString checkPathForSyncRootMarkingRecursive (const QString &path, FolderMan::NewFolderType folderType, const QUuid &accountUuid)
724
+ {
725
+ std::pair<QString, QUuid> existingTags = Utility::getDirectorySyncRootMarkings (path);
726
+ if (!existingTags.first .isEmpty ()) {
727
+ if (folderType == FolderMan::NewFolderType::SpacesFolder) {
728
+ if (existingTags.first == Theme::instance ()->orgDomainName ()) {
729
+ // Looks good, our app, let's check the account:
730
+ if (existingTags.second == accountUuid) {
731
+ // Nice, that's what we like, the sync root for our account in our app. No error.
732
+ return {};
733
+ } else {
734
+ return FolderMan::tr (" Folder '%1' is already in use by another account." ).arg (path);
735
+ }
736
+ } else {
737
+ // this is handled below: another application uses this as spces root folder
738
+ }
739
+ }
740
+
741
+ if (existingTags.first == Theme::instance ()->orgDomainName ()) {
742
+ // it's our application, so must be another space root
743
+ return FolderMan::tr (" Folder '%1' is already in use by another account." ).arg (path);
744
+ }
745
+ // another application uses this as spaces root folder
746
+ return FolderMan::tr (" Folder '%1' is already in use by application %2!" ).arg (path, existingTags.first );
728
747
}
729
748
730
749
QString parent = QFileInfo (path).path ();
731
750
if (parent == path) { // root dir, stop recursing
732
751
return {};
733
752
}
734
753
735
- return checkPathForSyncRootMarkingRecursive (parent);
754
+ return checkPathForSyncRootMarkingRecursive (parent, folderType, accountUuid );
736
755
}
737
756
738
- QString FolderMan::checkPathValidityRecursive (const QString &path)
757
+ QString FolderMan::checkPathValidityRecursive (const QString &path, FolderMan::NewFolderType folderType, const QUuid &accountUuid )
739
758
{
740
759
if (path.isEmpty ()) {
741
760
return FolderMan::tr (" No valid folder selected!" );
@@ -750,31 +769,45 @@ QString FolderMan::checkPathValidityRecursive(const QString &path)
750
769
return pathLenghtCheck.error ();
751
770
}
752
771
753
- const QFileInfo selFile (path);
754
- if (numberOfSyncJournals (selFile.filePath ()) != 0 ) {
755
- return FolderMan::tr (" The folder %1 is used in a folder sync connection!" ).arg (QDir::toNativeSeparators (selFile.filePath ()));
756
- }
757
-
758
- if (!selFile.exists ()) {
759
- const QString parentPath = selFile.path ();
772
+ const QFileInfo selectedPathInfo (path);
773
+ if (!selectedPathInfo.exists ()) {
774
+ const QString parentPath = selectedPathInfo.path ();
760
775
if (parentPath != path) {
761
- return checkPathValidityRecursive (parentPath);
776
+ return checkPathValidityRecursive (parentPath, folderType, accountUuid );
762
777
}
763
778
return FolderMan::tr (" The selected path does not exist!" );
764
779
}
765
780
766
- if (!selFile.isDir ()) {
781
+ if (numberOfSyncJournals (selectedPathInfo.filePath ()) != 0 ) {
782
+ return FolderMan::tr (" The folder %1 is used in a folder sync connection!" ).arg (QDir::toNativeSeparators (selectedPathInfo.filePath ()));
783
+ }
784
+
785
+ // At this point we know there is no syncdb in the parent hyrarchy, check for spaces sync root.
786
+
787
+ if (!selectedPathInfo.isDir ()) {
767
788
return FolderMan::tr (" The selected path is not a folder!" );
768
789
}
769
790
770
- if (!selFile .isWritable ()) {
791
+ if (!selectedPathInfo .isWritable ()) {
771
792
return FolderMan::tr (" You have no permission to write to the selected folder!" );
772
793
}
773
794
774
- return checkPathForSyncRootMarkingRecursive (path);
795
+ return checkPathForSyncRootMarkingRecursive (path, folderType, accountUuid );
775
796
}
776
797
777
- QString FolderMan::checkPathValidityForNewFolder (const QString &path) const
798
+ /*
799
+ * OC10 folder:
800
+ * - sync root not in syncdb folder
801
+ * - sync root not in spaces root
802
+ * with spaces:
803
+ * - spaces sync root not in syncdb folder
804
+ * - spaces sync root not in another spaces sync root
805
+ *
806
+ * - space not in syncdb folder
807
+ * - space *can* be in sync root
808
+ * - space not in spaces sync root of other account (check with account uuid)
809
+ */
810
+ QString FolderMan::checkPathValidityForNewFolder (const QString &path, NewFolderType folderType, const QUuid &accountUuid) const
778
811
{
779
812
// check if the local directory isn't used yet in another ownCloud sync
780
813
const auto cs = Utility::fsCaseSensitivity ();
@@ -789,20 +822,20 @@ QString FolderMan::checkPathValidityForNewFolder(const QString &path) const
789
822
}
790
823
if (FileSystem::isChildPathOf (folderDir, userDir)) {
791
824
return tr (" The local folder %1 already contains a folder used in a folder sync connection. "
792
- " Please pick another one !" )
825
+ " Please pick another local folder !" )
793
826
.arg (QDir::toNativeSeparators (path));
794
827
}
795
828
796
829
if (FileSystem::isChildPathOf (userDir, folderDir)) {
797
830
return tr (" The local folder %1 is already contained in a folder used in a folder sync connection. "
798
- " Please pick another one !" )
831
+ " Please pick another local folder !" )
799
832
.arg (QDir::toNativeSeparators (path));
800
833
}
801
834
}
802
835
803
- const auto result = checkPathValidityRecursive (path);
836
+ const auto result = checkPathValidityRecursive (path, folderType, accountUuid );
804
837
if (!result.isEmpty ()) {
805
- return tr (" %1 Please pick another one !" ).arg (result);
838
+ return tr (" %1 Please pick another local folder !" ).arg (result);
806
839
}
807
840
return {};
808
841
}
@@ -825,8 +858,9 @@ QString FolderMan::findGoodPathForNewSyncFolder(const QString &basePath, const Q
825
858
{
826
859
QString folder = normalisedPath;
827
860
for (int attempt = 2 ; attempt <= 100 ; ++attempt) {
861
+ // HvR: is this correct?
828
862
if (!QFileInfo::exists (folder)
829
- && FolderMan::instance ()->checkPathValidityForNewFolder (folder).isEmpty ()) {
863
+ && FolderMan::instance ()->checkPathValidityForNewFolder (folder, FolderMan::NewFolderType::SpacesSyncRootOrOC10SyncRoot, {} ).isEmpty ()) {
830
864
return canonicalPath (folder);
831
865
}
832
866
folder = normalisedPath + QStringLiteral (" (%1)" ).arg (attempt);
0 commit comments