[Pkg-owncloud-commits] [owncloud-client] 388/498: Wizards: allow adding a folder in a non-existing directory and create that folder

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:49:09 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit ec86d1a151a8061f4a177258ea0dfcd65f6a9653
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Tue Jul 28 12:14:52 2015 +0200

    Wizards: allow adding a folder in a non-existing directory and create that folder
    
    The owncloud wizard already created the directory, but the recent addition
    of FolderMan::checkPathValidityForNewFolder stopped allowing unexisting directories.
    
    So change FolderMan::checkPathValidityForNewFolder to allow non existing directory
    and whange the FolderWizard to create the directory if it does not exist.
    
    Issue #3492
---
 src/gui/accountsettings.cpp | 14 ++++++++++++++
 src/gui/folderman.cpp       | 16 +++++++++++-----
 src/gui/folderman.h         |  4 +++-
 test/testfolderman.h        | 35 +++++++++++++++++++++++++++++++----
 4 files changed, 59 insertions(+), 10 deletions(-)

diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index 8fce5aa..ae8522d 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -196,6 +196,20 @@ void AccountSettings::slotFolderWizardAccepted()
     definition.localPath    = folderWizard->field(QLatin1String("sourceFolder")).toString();
     definition.targetPath   = folderWizard->property("targetPath").toString();
 
+    {
+        QDir dir(definition.localPath);
+        if (!dir.exists()) {
+            qDebug() << "Creating folder" << definition.localPath;
+            if (!dir.mkpath(".")) {
+                QMessageBox::warning(this, tr("Folder creation failed"),
+                                     tr("<p>Could not create local folder <i>%1</i>.")
+                                        .arg(QDir::toNativeSeparators(definition.localPath)));
+                return;
+            }
+
+        }
+    }
+
     bool ignoreHidden = true;
     /* take the value from the definition of already existing folders. All folders have
      * the same setting so far, that's why it's ok to check the first one.
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index 765a877..ba19e6a 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -1097,15 +1097,21 @@ QString FolderMan::statusToString( SyncResult syncStatus, bool paused ) const
     return folderMessage;
 }
 
-QString FolderMan::checkPathValidityForNewFolder(const QString& path)
+QString FolderMan::checkPathValidityForNewFolder(const QString& path, bool forNewDirectory)
 {
+    if (path.isEmpty()) {
+        return tr("No valid folder selected!");
+    }
+
     QFileInfo selFile( path );
     QString userInput = selFile.canonicalFilePath();
 
-    QStringList warnStrings;
+    if (!selFile.exists()) {
+        return checkPathValidityForNewFolder(selFile.dir().path(), true);
+    }
 
     if( !selFile.isDir() ) {
-        return tr("No valid local folder selected!");
+        return tr("The selected path is not a directory!");
     }
 
     if ( !selFile.isWritable() ) {
@@ -1127,12 +1133,12 @@ QString FolderMan::checkPathValidityForNewFolder(const QString& path)
             return tr("The local path %1 is already an upload folder. Please pick another one!")
                 .arg(QDir::toNativeSeparators(userInput));
         }
-        if (QDir::cleanPath(folderDir).startsWith(QDir::cleanPath(userInput)+'/')) {
+        if (!forNewDirectory && QDir::cleanPath(folderDir).startsWith(QDir::cleanPath(userInput)+'/')) {
             return tr("An already configured folder is contained in the current entry.");
         }
 
         QString absCleanUserFolder = QDir::cleanPath(QDir(userInput).canonicalPath())+'/';
-        if (QDir::cleanPath(folderDir).startsWith(absCleanUserFolder) ) {
+        if (!forNewDirectory && QDir::cleanPath(folderDir).startsWith(absCleanUserFolder) ) {
             return tr("The selected folder is a symbolic link. An already configured "
                       "folder is contained in the folder this link is pointing to.");
         }
diff --git a/src/gui/folderman.h b/src/gui/folderman.h
index f791773..e1ca9f9 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -93,9 +93,11 @@ public:
      * 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 alrady.
      *
+     * \a forNewDirectory is internal and is used for recursion.
+     *
      * @returns an empty string if it is allowed, or an error if it is not allowed
      */
-    QString checkPathValidityForNewFolder(const QString &path);
+    QString checkPathValidityForNewFolder(const QString &path, bool forNewDirectory = false);
 
 signals:
     /**
diff --git a/test/testfolderman.h b/test/testfolderman.h
index 0fee89d..c1273ba 100644
--- a/test/testfolderman.h
+++ b/test/testfolderman.h
@@ -46,6 +46,11 @@ private slots:
         QVERIFY(dir2.mkpath("ownCloud2"));
         QVERIFY(dir2.mkpath("sub/free"));
         QVERIFY(dir2.mkpath("free2/sub"));
+        {
+            QFile f(dir.path() + "/sub/file.txt");
+            f.open(QFile::WriteOnly);
+            f.write("hello");
+        }
 
         FolderMan *folderman = FolderMan::instance();
         QCOMPARE(folderman, &_fm);
@@ -54,11 +59,15 @@ private slots:
 
 
         // those should be allowed
-        QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free").isNull());
-        QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/free2/").isNull());
+        QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free"), QString());
+        QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/free2/"), QString());
+        // Not an existing directory -> Ok
+        QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/bliblablu"), QString());
+        QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free/bliblablu"), QString());
+        QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/bliblablu/some/more"), QString());
 
-        // Not an existing directory -> Error
-        QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/bliblablu").isNull());
+        // A file -> Error
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/file.txt").isNull());
 
         // There are folders configured in those folders: -> ERROR
         QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1").isNull());
@@ -85,6 +94,24 @@ private slots:
         QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3").isNull());
         QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link4").isNull());
         QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3/folder").isNull());
+
+
+        // test some non existing sub path (error)
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/some/sub/path").isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/ownCloud2/blublu").isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/folder/g/h").isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3/folder/neu_folder").isNull());
+
+        // Subfolder of links
+        QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/link1/subfolder").isNull());
+        QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/link2/free/subfolder").isNull());
+
+        // Invalid paths
+        QVERIFY(!folderman->checkPathValidityForNewFolder("").isNull());
+
+        // Should not have the rights
+        QVERIFY(!folderman->checkPathValidityForNewFolder("/").isNull());
+        QVERIFY(!folderman->checkPathValidityForNewFolder("/usr/bin/somefolder").isNull());
 #else
         QSKIP("Test not supported with Qt4", SkipSingle);
 #endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list